﻿using SRB.Tg.DrawingStandard;
using SRB.Tg.Operate;
using System;
using System.Collections.Generic;
using System.Data;
using Teigha.DatabaseServices;
using Teigha.Geometry;

namespace SRB.Tg.Model
{
    public class PileInfo 
    {     
        DataRow dr;
        string configure_name = "";
        string pile_link_type = "桩基+承台";
        double pile_length=0;
        double pile_diameter = 0;
        double concrete_protect_layer = 0;
        string reinforcement_grade = "";
        double main_reinforcement_diameter = 0;
        int main_reinforcement_number = 0;
        double top_encryption_length = 0;
        double top_encryption_spacing = 0;
        double middle_encryption_length = 0;
        double middle_encryption_spacing = 0;
        double bottom_encryption_length = 0;
        double bottom_encryption_spacing = 0;
        double outer_strengthen_reinforcement_diameter = 0;//圆形加强钢筋直径
        double outer_strengthen_reinforcement_spacing = 0;//圆形加强钢筋间距
        double pile_penetration_depth = 0;//桩基伸入深度
        double top_pile_reinforcement_length = 0; //桩顶部加密区长度
        double spiral_reinforcement_diameter = 0;
        double pier_diameter = 0;
        double pier_protect_layer = 0;
        double pier_out_reinforcement_diameter = 0;
        double pier_main_diameter = 0;
        double pier_encryption_length = 0;
        double pier_encryption_spacing = 0;
        double pier_arc_length = 0;
        List<Tuple<int, eDB, int, double>> rebarLst = new List<Tuple<int, eDB, int, double>>();
        public PileInfo(DataRow row)
        {
            dr = row;
            configure_name = dr["configure_name"].ToString();
            pile_length = double.Parse(dr["pile_length"].ToString());
            pile_diameter = double.Parse(dr["pile_diameter"].ToString());
            pile_penetration_depth = double.Parse(dr["pile_penetration_depth"].ToString());
            concrete_protect_layer = double.Parse(dr["concrete_protect_layer"].ToString());
            reinforcement_grade = dr["reinforcement_grade"].ToString();
            main_reinforcement_diameter = double.Parse(dr["main_reinforcement_diameter"].ToString());
            main_reinforcement_number = int.Parse(dr["main_reinforcement_number"].ToString());
            top_encryption_length = double.Parse(dr["top_encryption_length"].ToString());
            top_encryption_spacing = double.Parse(dr["top_encryption_spacing"].ToString());
            middle_encryption_length = double.Parse(dr["middle_encryption_length"].ToString());
            middle_encryption_spacing = double.Parse(dr["middle_encryption_spacing"].ToString());
            bottom_encryption_length = double.Parse(dr["bottom_encryption_length"].ToString());
            bottom_encryption_spacing = double.Parse(dr["bottom_encryption_spacing"].ToString());
            outer_strengthen_reinforcement_diameter = double.Parse(dr["outer_strengthen_reinforcement_diameter"].ToString());
            outer_strengthen_reinforcement_spacing = double.Parse(dr["outer_strengthen_reinforcement_spacing"].ToString());
            top_pile_reinforcement_length = double.Parse(dr["top_pile_reinforcement_length"].ToString());
            spiral_reinforcement_diameter = double.Parse(dr["spiral_reinforcement_diameter"].ToString());
            pile_link_type = dr["pile_link_type"].ToString();
            #region 墩身部分
            if (pile_link_type != "桩基+承台")
            {
                pier_diameter = double.Parse(dr["pier_diameter"].ToString());
                pier_protect_layer = double.Parse(dr["pier_protect_layer"].ToString());
                pier_out_reinforcement_diameter = double.Parse(dr["pier_out_reinforcement_diameter"].ToString());
                pier_main_diameter = double.Parse(dr["pier_main_diameter"].ToString());
                pier_encryption_length = double.Parse(dr["pier_encryption_length"].ToString());
                pier_encryption_spacing = double.Parse(dr["pier_encryption_spacing"].ToString());
                pier_arc_length= double.Parse(dr["pier_arc_length"].ToString());
            }
            #endregion
        }
        public void DrawingPile(Database db, int OverAllScale)
        {
          
            #region 绘制图形
            Extents2d ExtPile, ExtSectionPile, ExtCal;
            Point2d RefPtPile, RefPtSectionPile, RefPtCal, RefPtDetail;
            RefPtPile = Point2d.Origin;
            RefPtSectionPile = RefPtPile.C2D(pile_length*0.5+pile_diameter*3);
            List<Extents2d> lstDetail = new List<Extents2d>();
            if (pile_link_type == "桩基+承台")
            {
                PlotPile(ref db, out ExtPile, RefPtPile, OverAllScale);

                PlotSection(ref db, out ExtSectionPile, RefPtSectionPile, OverAllScale);
                double w = ExtPile.W();
                RefPtDetail = RefPtPile.C2D(-ExtPile.W() * 0.5, -ExtPile.L() * 1.1);
             
                PlotSample(ref db, ref lstDetail, RefPtDetail, 1, w * 0.2);

                double wS = ExtSectionPile.W();
                RefPtCal = RefPtSectionPile.C2D(0, -ExtSectionPile.L() * 1.1);

                ExtCal = new Extents2d(RefPtCal, RefPtCal);
                PlotCalculate(ref db, ref ExtCal, RefPtCal, 1);
            }
            else
            {
                PlotPilePier(db, out ExtPile, RefPtPile, OverAllScale);

                PlotPilePierSection(ref db, out ExtSectionPile, RefPtSectionPile, OverAllScale);
                double w = ExtPile.W();
                RefPtDetail = RefPtPile.C2D(-ExtPile.W() * 0.5, -ExtPile.L() * 1.1);

                PlotPilePierSample(ref db, ref lstDetail, RefPtDetail, 1, w * 0.2);

                double wS = ExtSectionPile.W();
                RefPtCal = RefPtSectionPile.C2D(0, -ExtSectionPile.L() * 1.1);

                ExtCal = new Extents2d(RefPtCal, RefPtCal);
                PlotPilePierCalculate(ref db, ref ExtCal, RefPtCal, 1);
            }
            #endregion

            #region 模型空间到布局空间投影处理
            Point2d tKPoint = Point2d.Origin;
            LayoutTools.CreateSerPileLayout(db, "图纸", ExtPile, ExtSectionPile, lstDetail, ExtCal, Extensions.leftWidth, Extensions.rightWidth, Extensions.bottomHeight, Extensions.topHeight, 5,ref tKPoint);
            string dwgPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "Template\\RebarSerbia.dwg";
            string _blcName = "TK";
            BlockPlot.InsertBlockToPaperByDwg(db, dwgPath, _blcName, "H钢筋", tKPoint.C3D(), 1, 0, true, false);

            // 文字         
            string text = @"ПРОЈЕКАТ ПРИЛАЗНИХ КОНСТРУКЦИЈА-M09 (KM1+109.500~KM1+191.500)";
            Point3d p0 = tKPoint.C3D(-185 + 44.7, 38);
            Extents2d ext = new Extents2d();
            TextPloter.AddMText2Paper(db,p0, ref ext, text, 1, 2, 120, Extensions.curFont);
            string text1 = @"DESIGN OF APPROACH BRIDGE-M09 (KM1+109.500~KM1+191.500) ";
            Point3d p1 = tKPoint.C3D(-185 + 44.7, 38 - 3);
            TextPloter.AddMText2Paper(db,p1, ref ext, text1, 1, 2, 120, Extensions.curFont);

            string text2 = @"356-PGD-2/1.3.9";
            Point3d p2 = tKPoint.C3D(-185 + 153, 30);
            TextPloter.AddMText2Paper(db,p2, ref ext, text2, 1, 2.2, 40, Extensions.curFont);
            string text3 = @"1:" + OverAllScale * 10;
            Point3d p3 = tKPoint.C3D(-185 + 153, 20);
            TextPloter.AddMText2Paper(db,p3, ref ext, text3, 1, 2.2, 40, Extensions.curFont);
            #endregion
        }

        #region  "桩基+墩身"
        private void PlotPilePier(Database db, out Extents2d ext, Point2d insertPoint, int _scale)
        {
            eDB N2 = (eDB)Enum.Parse(typeof(eDB), spiral_reinforcement_diameter.ToString()); ;
            eDB N5 = eDB.DB12;
            eDB mainDB = (eDB)Enum.Parse(typeof(eDB), main_reinforcement_diameter.ToString());
            //eDB main = eDB.DB32;
            eDB N4 = (eDB)Enum.Parse(typeof(eDB), outer_strengthen_reinforcement_diameter.ToString());
            Tuple<int, eDB, int, double> tuple;

            double scale = _scale;//绘制比例
            ext = new Extents2d(insertPoint, insertPoint);
            TextPloter.AddTitleS(db,insertPoint, ref ext, "PILE REINFORCEMENT PLAN", @"ПЛАН АРМАТУРЕ ШИПОВАПИ", "(1:" + _scale * 10 + ")", scale);

            Point2d ptGZ = insertPoint.C2D(0, -30 * scale);
            #region 绘制轮廓
            //绘制桩基外轮廓
            PLPloter.AddPloy4(db, ptGZ, pile_length * 0.5, pile_length * 0.5, pile_diameter, ref ext, "HM细线");
            //绘制墩身外轮廓
            double hPierD = (pile_diameter - pier_diameter) * 0.5;
            PLPloter.AddLine(db,ptGZ.C2D(-pile_length * 0.5 - 10 * scale - pile_penetration_depth, -hPierD), ptGZ.C2D(-pile_length * 0.5, -hPierD), ref ext, "HM细线");
            PLPloter.AddLine(db,ptGZ.C2D(-pile_length * 0.5 - 10 * scale - pile_penetration_depth, -hPierD - pier_diameter), ptGZ.C2D(-pile_length * 0.5, -hPierD - pier_diameter), ref ext, "HM细线");
            PLPloter.CreateBreakLine(db, ref ext, ptGZ.C2D(-pile_length * 0.5 - 10 * scale - pile_penetration_depth, -hPierD - pier_diameter - 5 * scale), ptGZ.C2D(-pile_length * 0.5 - 10 * scale - pile_penetration_depth, -hPierD + 5 * scale), scale * 10);

            double hPierID = spiral_reinforcement_diameter * 0.1 * 2 + pier_main_diameter * 0.1 + pier_protect_layer;
            PLPloter.AddScaleLine(db, ptGZ.C2D(-pile_length * 0.5 - 10 * scale - pile_penetration_depth, -hPierD - hPierID), ptGZ.C2D(-pile_length * 0.5, -hPierD - hPierID), ref ext, "H虚线", scale);
            PLPloter.AddScaleLine(db, ptGZ.C2D(-pile_length * 0.5 - 10 * scale - pile_penetration_depth, -hPierD - pier_diameter + hPierID), ptGZ.C2D(-pile_length * 0.5, -hPierD - pier_diameter + hPierID), ref ext, "H虚线", scale);

            //PLPloter.AddPloy4(ptGZ.C2D(-pile_length * 0.5 - pile_penetration_depth, pile_diameter * 0.3 * 0.5), pile_penetration_depth, pile_penetration_depth, pile_diameter + pile_diameter * 0.3, ref ext, "HM细线");
            DimPloter.DimAli(db,ptGZ.C3D(pile_length * 0.5, -30 * scale), ptGZ.C3D(-pile_length * 0.5, -30 * scale), ptGZ.C3D(0, 20 * scale), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
            DimPloter.DimAli(db,ptGZ.C3D(-pile_length * 0.5, -30 * scale), ptGZ.C3D(-pile_length * 0.5 - pile_penetration_depth, -30 * scale), ptGZ.C3D(0, 20 * scale), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
            #endregion

            #region 2号螺旋筋
            double h20 = 15 * scale;
            //绘制2号螺旋筋
            Point2d ptStart = insertPoint.C2D(pile_length * 0.5 - concrete_protect_layer * 2, -30 * scale - pile_diameter * 0.5);
            Point2d ptStart0 = insertPoint.C2D(pile_length * 0.5, -30 * scale - pile_diameter * 0.5);
            Point2d bottomEnd = new Point2d();
            SteelBarS.CreatePartSteelBar(db, ref ext, out bottomEnd, ptStart, pile_diameter - concrete_protect_layer * 2 - spiral_reinforcement_diameter * 0.1, bottom_encryption_length, bottom_encryption_spacing, true, eLocation.Bottom);
            Point2d ptLS = ptStart.C2D(0, -pile_diameter * 0.5 - pile_diameter * 0.3 * 0.5 - 20);
            PLPloter.AddLine(db,ptLS.C2D(), ptLS.C2D(-bottom_encryption_length), ref ext, "HM细线");
            Point3d txt21 = GeTools.MidPoint(ptLS.C3D(), ptLS.C3D(-bottom_encryption_length));
            TextPloter.AddDBTextWithCirle(db,txt21.C3D(0, -2.5 * scale), ref ext, (int)(bottom_encryption_length / bottom_encryption_spacing) + "%%C" + spiral_reinforcement_diameter + "(t=" + bottom_encryption_spacing + ")", "2", scale);
            PLPloter.AddLine(db,ptLS.C2D(), ptLS.C2D(0, 10), ref ext, "HM细线");
            PLPloter.AddLine(db,ptLS.C2D(-bottom_encryption_length), ptLS.C2D(-bottom_encryption_length, 10), ref ext, "HM细线");
            DimPloter.DimAli(db,ptLS.C3D(), ptLS.C3D(-bottom_encryption_length), ptLS.C3D(0, -h20), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
            DimPloter.DimAli(db,ptStart.C3D(), ptStart0.C3D(), ptLS.C3D(0, -h20), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
            Point2d ptLS0 = insertPoint.C2D(pile_length * 0.5, -30 * scale - pile_diameter);
            DimPloter.DimAli(db,ptLS0.C3D(), ptLS0.C3D(0, pile_diameter), ptLS0.C3D(5 * scale, 0), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);

            Point2d middleEnd = new Point2d();
            SteelBarS.CreatePartSteelBar(db, ref ext, out middleEnd, bottomEnd, pile_diameter - concrete_protect_layer * 2 - spiral_reinforcement_diameter * 0.1, middle_encryption_length, middle_encryption_spacing, true, eLocation.Middle);
            ptLS = ptLS.C2D(-bottom_encryption_length);
            PLPloter.AddLine(db,ptLS.C2D(), ptLS.C2D(-middle_encryption_length), ref ext, "HM细线");
            Point3d txt22 = GeTools.MidPoint(ptLS.C3D(), ptLS.C3D(-middle_encryption_length));
            TextPloter.AddDBTextWithCirle(db,txt22.C3D(0, -2.5 * scale), ref ext, (int)(middle_encryption_length / middle_encryption_spacing) + "%%C" + spiral_reinforcement_diameter + "(t=" + middle_encryption_spacing + ")", "2", scale);
            PLPloter.AddLine(db,ptLS.C2D(), ptLS.C2D(0, 10), ref ext, "HM细线");
            PLPloter.AddLine(db,ptLS.C2D(-middle_encryption_length), ptLS.C2D(-middle_encryption_length, 10), ref ext, "HM细线");
            DimPloter.DimAli(db,ptLS.C3D(), ptLS.C3D(-middle_encryption_length), ptLS.C3D(0, -h20), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);

            Point2d topEnd = new Point2d();
            SteelBarS.CreatePartSteelBar(db, ref ext, out topEnd, middleEnd, pile_diameter - concrete_protect_layer * 2 - spiral_reinforcement_diameter * 0.1, top_encryption_length, top_encryption_spacing, true, eLocation.Middle, false);
            ptLS = ptLS.C2D(-middle_encryption_length);
            PLPloter.AddLine(db,ptLS.C2D(), ptLS.C2D(-top_encryption_length), ref ext, "HM细线");
            Point3d txt23 = GeTools.MidPoint(ptLS.C3D(), ptLS.C3D(-top_encryption_length));
            TextPloter.AddDBTextWithCirle(db,txt23.C3D(0, -2.5 * scale), ref ext, (int)(top_encryption_length / top_encryption_spacing) + "%%C" + spiral_reinforcement_diameter + "(t=" + top_encryption_spacing + ")", "2", scale);
            PLPloter.AddLine(db,ptLS.C2D(), ptLS.C2D(0, 10), ref ext, "HM细线");
            PLPloter.AddLine(db,ptLS.C2D(-top_encryption_length), ptLS.C2D(-top_encryption_length, 10), ref ext, "HM细线");
            DimPloter.DimAli(db,ptLS.C3D(), ptLS.C3D(-top_encryption_length), ptLS.C3D(0, -h20), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
            //TextPloter.AddDBText(db,topEnd.C3D(-2 * scale, pile_diameter * 0.1), ref ext, "PileCap", scale, 3, "SRB.HT", 0, TextHorizontalMode.TextRight, TextVerticalMode.TextBottom);

            Point2d topPier = new Point2d();
            SteelBarS.CreatePierPartSteelBar(db, ref ext, out topPier, topEnd, pile_diameter - concrete_protect_layer * 2 - spiral_reinforcement_diameter * 0.1, pier_diameter - pier_protect_layer * 2 - spiral_reinforcement_diameter * 0.1, pier_encryption_length, pier_encryption_spacing, true, eLocation.Top);
            ptLS = ptLS.C2D(-top_encryption_length);
            PLPloter.AddLine(db,ptLS.C2D(), ptLS.C2D(-pier_encryption_length), ref ext, "HM细线");
            Point3d txt32 = GeTools.MidPoint(ptLS.C3D(), ptLS.C3D(-pier_encryption_length));
            TextPloter.AddDBTextWithCirle(db,txt32.C3D(0, -2.5 * scale), ref ext, (int)(pier_encryption_length / pier_encryption_spacing) + "%%C" + spiral_reinforcement_diameter + "(t=" + top_encryption_spacing + ")", "3", scale);
            PLPloter.AddLine(db,ptLS.C2D(), ptLS.C2D(0, 10), ref ext, "HM细线");
            PLPloter.AddLine(db,ptLS.C2D(-pier_encryption_length), ptLS.C2D(-pier_encryption_length, 10), ref ext, "HM细线");
            DimPloter.DimAli(db,ptLS.C3D(), ptLS.C3D(-pier_encryption_length), ptLS.C3D(0, -h20), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
            #region 
            SteelBarS.CreateRibSection(db, ptStart0.C2D(-pile_length + 30, pile_diameter * 0.5 + 2 * scale), "1", ref ext, "H文本", scale);
            SteelBarS.CreateRibSection(db, ptStart0.C2D(-pile_length + 30, -pile_diameter * 0.5 - 2 * scale), "1", ref ext, "H文本", scale);
            SteelBarS.CreateRibSection(db, ptStart0.C2D(-bottom_encryption_length - middle_encryption_length + middle_encryption_length * 0.1, pile_diameter * 0.5 + 2 * scale), "2", ref ext, "H文本", scale);
            SteelBarS.CreateRibSection(db, ptStart0.C2D(-bottom_encryption_length - middle_encryption_length + middle_encryption_length * 0.1, -pile_diameter * 0.5 - 2 * scale), "2", ref ext, "H文本", scale);
            SteelBarS.CreateRibSection(db, ptStart0.C2D(-bottom_encryption_length + bottom_encryption_length * 0.1, pile_diameter * 0.5 + 2 * scale), "3", ref ext, "H文本", scale);
            SteelBarS.CreateRibSection(db, ptStart0.C2D(-bottom_encryption_length + bottom_encryption_length * 0.1, -pile_diameter * 0.5 - 2 * scale), "3", ref ext, "H文本", scale);


            #endregion

            double tL = GlobalFuncs.GetSpiralLength(top_encryption_length, spiral_reinforcement_diameter * 0.1, top_encryption_spacing, pile_diameter, concrete_protect_layer);
            double mL = GlobalFuncs.GetSpiralLength(middle_encryption_length, spiral_reinforcement_diameter * 0.1, middle_encryption_spacing, pile_diameter, concrete_protect_layer);
            double bL = GlobalFuncs.GetSpiralLength(bottom_encryption_length, spiral_reinforcement_diameter * 0.1, bottom_encryption_spacing, pile_diameter, concrete_protect_layer);
            double pBL = GlobalFuncs.GetSpiralTopLength(spiral_reinforcement_diameter * 0.1, 0.5, pile_diameter, concrete_protect_layer);
            double pTL = GlobalFuncs.GetSpiralTopLength( spiral_reinforcement_diameter * 0.1, 0.5, pier_diameter, pier_protect_layer);
            double rT = GlobalFuncs.GetSpiraldia(spiral_reinforcement_diameter * 0.1,  pier_diameter, pier_protect_layer);
            double rB= GlobalFuncs.GetSpiraldia(spiral_reinforcement_diameter * 0.1,  pile_diameter, concrete_protect_layer);
            double pL = GlobalFuncs.GetSpiralLength(pier_encryption_length, (rT+ rB) * 0.5, pier_encryption_spacing);
            double L = (tL + mL + bL+ pBL+ pTL+pL);
            tuple = new Tuple<int, eDB, int, double>(2, N2, 1, L);
            rebarLst.Add(tuple);
            #endregion

            #region 1#,3#，6#钢筋，以及搭接动态绘制算法处理

            double len = 175;//搭接
            //double h0 = 14 * scale;
            double h1 = 5 * scale;
            double h2 = 10 * scale;
            double h3 = 15 * scale;
            double hPier = 20 * scale;
            double pierArcl = pier_arc_length;
            //绘制1号钢筋
            Point2d ptStart1 = insertPoint.C2D(pile_length * 0.5 - concrete_protect_layer, -30 * scale - pile_diameter * 0.5);
            double rebarLength = top_encryption_length + middle_encryption_length + bottom_encryption_length + pier_encryption_length;// + concrete_protect_layer * 2;
            //PLPloter.AddLine(db,ptStart1.C2D(0, pile_diameter * 0.5 - concrete_protect_layer - spiral_reinforcement_diameter * 0.1*2), ptStart1.C2D(-rebarLength, pile_diameter * 0.5 - concrete_protect_layer - spiral_reinforcement_diameter * 0.1 * 2), ref ext, "H钢筋");
            //PLPloter.AddLine(db,ptStart1.C2D(0, -(pile_diameter * 0.5 - concrete_protect_layer - spiral_reinforcement_diameter * 0.1 * 2)), ptStart1.C2D(-rebarLength, -(pile_diameter * 0.5 - concrete_protect_layer - spiral_reinforcement_diameter * 0.1 * 2)), ref ext, "H钢筋");
            double layerPile = pile_diameter * 0.5 - concrete_protect_layer - 2 * spiral_reinforcement_diameter * 0.1 - main_reinforcement_diameter * 0.1;
            double layerPier = pier_diameter * 0.5 - pier_protect_layer - 2 * spiral_reinforcement_diameter * 0.1 - pier_main_diameter * 0.1;
            double layerDiv = layerPile - layerPier;
            Line line1, line2;
            SteelBarS.CreateMainSample(db, ref ext, ptGZ.C2D(-pile_length * 0.5 - pile_penetration_depth, -hPierD - hPierID + pier_main_diameter * 0.1), out line1, out line2, pile_penetration_depth, pile_length - concrete_protect_layer - pier_encryption_length, pier_encryption_length, true, layerDiv, pierArcl);
            SteelBarS.CreateMainSample(db, ref ext, ptGZ.C2D(-pile_length * 0.5 - pile_penetration_depth, -hPierD - pier_diameter + hPierID - pier_main_diameter * 0.1), out line1, out line2, pile_penetration_depth, pile_length - concrete_protect_layer - pier_encryption_length, pier_encryption_length, false, layerDiv, pierArcl);


            //搭接处理
            #region 1#钢筋 搭接墩柱
            double angM = Math.Round(360.0 / (main_reinforcement_number), 2);
            double LB = 2 * (pile_diameter * 0.5 - concrete_protect_layer - main_reinforcement_diameter * 0.1) * Math.Sin(GeTools.DegreeToRadian(angM * 0.5));
            double angM1 = Math.Round(360.0 / (main_reinforcement_number*0.5), 2);
            double LB1 = 2 * (pile_diameter * 0.5 - concrete_protect_layer - main_reinforcement_diameter * 0.1) * Math.Sin(GeTools.DegreeToRadian(angM1 * 0.5));

            double R = 100;
            double pileCap = 1200 - 2 - pile_penetration_depth - pierArcl;
            Point2d ptPierStart = ptGZ.C2D(-pile_length * 0.5 - pile_penetration_depth+5, -pile_diameter - pile_diameter * 0.5 - h1 - hPierID + pier_main_diameter * 0.1 - hPier);
          
            SteelBarS.CreateMainSample(db, ref ext, ptPierStart,out line1,out line2, pile_penetration_depth, pileCap, pier_encryption_length, true, layerDiv, pierArcl);
            Point3d pttxtPier = GeTools.MidPoint(ptPierStart.C3D(0, 0), ptPierStart.C3D(pile_penetration_depth, 0));
            TextPloter.AddDBTextWithCirle(db,pttxtPier.C3D(0, -2.5 * scale), ref ext, (int)(main_reinforcement_number) + "%%C" + main_reinforcement_diameter + "/" + LB.ToString("0.0"), "1", scale);
            TextPloter.AddDBText(db,pttxtPier.C3D(), ref ext, "L=1200.0", scale, 2.5, "SRB.HT", 0, TextHorizontalMode.TextLeft);
            DimPloter.DimAli(db,ptPierStart.C3D(0), ptPierStart.C3D(pile_penetration_depth), ptPierStart.C3D(0,  -h2), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
            DimPloter.DimRot(db, ptPierStart.C3D(pile_penetration_depth), ptPierStart.C3D(pile_penetration_depth + pierArcl, layerDiv), ptPierStart.C3D(0,  -h2), ref ext, 0, scale, "", Unit.Centimeter, Unit.Centimeter);

            DimPloter.DimAli(db,ptPierStart.C3D(pile_penetration_depth + pierArcl), ptPierStart.C3D(pile_penetration_depth + pierArcl, layerDiv), ptPierStart.C3D(pile_penetration_depth + pierArcl+8*scale, layerDiv), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
            DimPloter.DimAli(db,ptPierStart.C3D(pile_penetration_depth + pierArcl, layerDiv), ptPierStart.C3D(pile_penetration_depth + pierArcl + pileCap, layerDiv), ptPierStart.C3D(0, -h2), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
            DimPloter.DimRadius(db,ptPierStart.C3D(pile_penetration_depth - 5, -R), ptPierStart.C3D(pile_penetration_depth,0), 3 * scale, ref ext, scale,"", Unit.Centimeter, Unit.Centimeter);
            DimPloter.DimRadius(db,ptPierStart.C3D(pile_penetration_depth + pierArcl+5, layerDiv+R), ptPierStart.C3D(pile_penetration_depth + pierArcl,layerDiv), 3 * scale, ref ext, scale,"", Unit.Centimeter, Unit.Centimeter);
            string ang =GeTools.RadianToDegree( Math.Atan(layerDiv / pierArcl)).ToString("0.0");
            DimPloter.DimAng(db,line1, line2, ptPierStart.C3D(pile_penetration_depth + pierArcl*0.8,layerDiv*0.5), ref ext,scale, ang, Unit.Centimeter, Unit.Centimeter);
            #endregion

            int divnum = (int)((rebarLength - pierArcl - pileCap-5 ) / (1200 - len));
            int divCap = (int)((rebarLength - pierArcl - pileCap-5 ) % (1200 - len));
            
            #region  搭接处理6# ，7#
            Point2d ptPileStart = ptPierStart.C2D(pile_penetration_depth+pierArcl + pileCap - len, layerDiv - pier_main_diameter * 0.1*2);
            string num = "6";
            for (int i = 0; i < divnum; i++)
            {
                if (i % 2 == 0)
                {
                    PLPloter.AddLine(db,ptPileStart.C2D((1200 - len) * i, 0), ptPileStart.C2D(1200 * (i + 1) - len * i, 0), ref ext, "H钢筋");
                    Point3d pttxt1 = GeTools.MidPoint(ptPileStart.C3D(1200 * i, 0), ptPileStart.C3D(1200 * (i + 1), 0));
                    if (i == 0)
                        TextPloter.AddDBTextWithCirle(db,pttxt1.C3D(0, -2.5 * scale), ref ext, (int)(main_reinforcement_number) + "%%C"+main_reinforcement_diameter+"/" + LB.ToString("0.0"), num, scale);
                    else
                        TextPloter.AddDBTextWithCirle(db,pttxt1.C3D(0, -2.5 * scale), ref ext, (int)(main_reinforcement_number * 0.5) + "%%C" + main_reinforcement_diameter + "/" + LB1.ToString("0.0"), num, scale);
                    TextPloter.AddDBText(db,pttxt1.C3D(), ref ext, "L=1200.0", scale, 2.5, "SRB.HT", 0, TextHorizontalMode.TextLeft);
                    DimPloter.DimAli(db,ptPileStart.C3D((1200 - len) * i, 0), ptPileStart.C3D(1200 * (i + 1) - len * i, 0), ptPileStart.C3D(0, -h1 - 3 * scale), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
                    //DimPloter.DimAli(db,ptPileStart.C3D((1200 - len) * i, 0), ptPileStart.C3D(1200 * (i + 1) - len * i, 0), ptPileStart.C3D(0, h1), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
                    if (i < divnum - 1)
                    {
                        DimPloter.DimAli(db,ptPileStart.C3D(1200 * (i + 1) - len * i), ptPileStart.C3D((1200 - len) * (i + 1)), ptPileStart.C3D(0, h1), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
                    }
                    else
                    {
                        if (divCap > 0)
                            DimPloter.DimAli(db,ptPileStart.C3D(1200 * (i + 1) - len * i), ptPileStart.C3D((1200 - len) * (i + 1)), ptPileStart.C3D(0, h1), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
                    }
                    if (i == 0)
                    {
                        DimPloter.DimAli(db,ptPileStart.C3D(), ptPileStart.C3D(len), ptPileStart.C3D(0, h1), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);

                    }
                }
                else
                {
                    PLPloter.AddLine(db,ptPileStart.C2D((1200 - len) * i, main_reinforcement_diameter * 0.1 * 2), ptPileStart.C2D(1200 * (i + 1) - len * i, main_reinforcement_diameter * 0.1 * 2), ref ext, "H钢筋");
                    Point3d pttxt2 = GeTools.MidPoint(ptPileStart.C3D((1200 - len) * i, main_reinforcement_diameter * 0.1 * 2), ptPileStart.C3D(1200 * (i + 1) - len * i, main_reinforcement_diameter * 0.1 * 2));
                    TextPloter.AddDBTextWithCirle(db,pttxt2.C3D(0, 2.5 * scale), ref ext, (int)(main_reinforcement_number * 0.5) + "%%C" + main_reinforcement_diameter + "/" + LB1.ToString("0.0"), num, scale);
                    TextPloter.AddDBText(db,pttxt2.C3D(0, -4 * scale), ref ext, "L=1200.0", scale, 2.5, "SRB.HT", 0, TextHorizontalMode.TextLeft);

                    DimPloter.DimAli(db,ptPileStart.C3D((1200 - len) * i, main_reinforcement_diameter * 0.1 * 2), ptPileStart.C3D(1200 * (i + 1) - len * i, main_reinforcement_diameter * 0.1 * 2), ptPileStart.C3D(0, h2), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
                    //if (divCap > 0)
                    if (i < divnum - 1)
                    {
                        DimPloter.DimAli(db,ptPileStart.C3D(1200 * (i + 1) - len * i, main_reinforcement_diameter * 0.1 * 2), ptPileStart.C3D((1200 - len) * (i + 1), main_reinforcement_diameter * 0.1 * 2), ptPileStart.C3D(0, h1), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
                    }
                    else
                    {
                        if (divCap > 0)
                            DimPloter.DimAli(db,ptPileStart.C3D(1200 * (i + 1) - len * i, main_reinforcement_diameter * 0.1 * 2), ptPileStart.C3D((1200 - len) * (i + 1), main_reinforcement_diameter * 0.1 * 2), ptPileStart.C3D(0, h1), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
                    }
                }
            }

            if (divCap > 0)
            {
                if (divnum > 0)
                    num = "7";
                if (divnum % 2 == 0)
                {

                    PLPloter.AddLine(db,ptPileStart.C2D((1200 - len) * divnum, 0), ptPileStart.C2D((1200 - len) * divnum+divCap + len,0), ref ext, "H钢筋");
                    Point3d pttxt3 = GeTools.MidPoint(ptPileStart.C3D((1200 - len) * divnum, 0), ptPileStart.C3D((1200 - len) * divnum + divCap + len, 0));
                    TextPloter.AddDBTextWithCirle(db,pttxt3.C3D(0, -2.5 * scale), ref ext, (int)(main_reinforcement_number * 0.5) + "%%C" + main_reinforcement_diameter + "/" + LB1.ToString("0.0"), num, scale);
                    TextPloter.AddDBText(db,pttxt3.C3D(), ref ext, "L=" + (divCap + len).ToString("0.0"), scale, 2.5, "SRB.HT", 0, TextHorizontalMode.TextLeft);
                    DimPloter.DimAli(db,ptPileStart.C3D((1200 - len) * divnum, 0), ptPileStart.C3D((1200 - len) * divnum + divCap + len, 0), ptPileStart.C3D(0, -h1-3*scale), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);

                }
                else
                {
                    PLPloter.AddLine(db,ptPileStart.C2D((1200 - len) * divnum, main_reinforcement_diameter * 0.1 * 2), ptPileStart.C2D((1200 - len) * divnum + divCap + len, main_reinforcement_diameter * 0.1 * 2), ref ext, "H钢筋");
                    Point3d pttxt3 = GeTools.MidPoint(ptPileStart.C3D((1200 - len) * divnum, main_reinforcement_diameter * 0.1 * 2), ptPileStart.C3D((1200 - len) * divnum + divCap + len, main_reinforcement_diameter * 0.1 * 2));
                    TextPloter.AddDBTextWithCirle(db,pttxt3.C3D(0, 2.5 * scale), ref ext, (int)(main_reinforcement_number * 0.5) + "%%C" + main_reinforcement_diameter + "/" + LB1.ToString("0.0"), num, scale);
                    TextPloter.AddDBText(db,pttxt3.C3D(0, -4 * scale), ref ext, "L=" + (divCap + len).ToString("0.0"), scale, 2.5, "SRB.HT", 0, TextHorizontalMode.TextLeft);
                    DimPloter.DimAli(db,ptPileStart.C3D((1200 - len) * divnum, main_reinforcement_diameter * 0.1 * 2), ptPileStart.C3D((1200 - len) * divnum + divCap + len, main_reinforcement_diameter * 0.1 * 2), ptPileStart.C3D(0, h2), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);

                }
            }


            #endregion
            int no1 = 1;

            int no6 = 6;
            int no7 = 7;
            tuple = new Tuple<int, eDB, int, double>(no1, mainDB, main_reinforcement_number, 1200);
            rebarLst.Add(tuple);
            if (divnum == 0)
            {
                tuple = new Tuple<int, eDB, int, double>(no1, mainDB, (int)(main_reinforcement_number*0.5), divCap+len);
                rebarLst.Add(tuple);
            }
            else 
            {
                tuple = new Tuple<int, eDB, int, double>(no6, mainDB, (int)(main_reinforcement_number * 0.5)* (divnum+1), 1200);
                rebarLst.Add(tuple);

                if (divCap > 0)
                {
                    tuple = new Tuple<int, eDB, int, double>(no7, mainDB, (int)(main_reinforcement_number * 0.5), divCap + len);
                    rebarLst.Add(tuple);

                }
            }
           


            #endregion

            #region 4#钢筋处理
            Point2d ptStart4 = insertPoint.C2D(-pile_length * 0.5, -30 * scale - pile_diameter * 0.5);
            Point2d pt4 = ptStart4.C2D(0, -pile_diameter * 0.5 - pile_diameter * 0.3 * 0.5 - 20 - 7 * scale);
            int num4 = (int)(pile_length / outer_strengthen_reinforcement_spacing);
            Point3d txt4 = GeTools.MidPoint(pt4.C3D(50), pt4.C3D(50 + outer_strengthen_reinforcement_spacing * (num4 - 1)));
            TextPloter.AddDBTextWithCirle(db,txt4.C3D(0, -2.5 * scale), ref ext, num4 + "%%C" + outer_strengthen_reinforcement_diameter + "/" + outer_strengthen_reinforcement_spacing, "4", scale);

            Point2d ptStart40 = insertPoint.C2D(-pile_length * 0.5, -30 * scale - pile_diameter * 0.5);
            for (int i = 1; i < num4; i++)
            {
                if (i > 1)
                    PLPloter.AddLine(db,pt4.C2D(50 + outer_strengthen_reinforcement_spacing * (i - 1), 0), pt4.C2D(50 + outer_strengthen_reinforcement_spacing * i, 0), ref ext, "HM细线");
                if (i == 1)
                {
                    //PLPloter.AddLine(db,pt4.C2D(50, 0), pt4.C2D(50, 10), ref ext, "HM细线");
                    //PLPloter.AddLine(db,ptStart40.C2D(50, pile_diameter * 0.5 - concrete_protect_layer - main_reinforcement_diameter * 0.1 - outer_strengthen_reinforcement_diameter * 0.1), ptStart40.C2D(50, -(pile_diameter * 0.5 - concrete_protect_layer - main_reinforcement_diameter * 0.1 - outer_strengthen_reinforcement_diameter * 0.1)), ref ext, "H钢筋", 2);
                    PLPloter.AddLineWithColor(db,ptStart40.C2D(50 + outer_strengthen_reinforcement_spacing * i, pile_diameter * 0.5 - concrete_protect_layer - main_reinforcement_diameter * 0.1), ptStart40.C2D(50 + outer_strengthen_reinforcement_spacing * i, -(pile_diameter * 0.5 - concrete_protect_layer - main_reinforcement_diameter * 0.1)), ref ext, "H钢筋", 2);
                }
                else
                    PLPloter.AddLineWithColor(db,ptStart40.C2D(50 + outer_strengthen_reinforcement_spacing * i, pile_diameter * 0.5 - concrete_protect_layer - spiral_reinforcement_diameter * 0.1 * 3), ptStart40.C2D(50 + outer_strengthen_reinforcement_spacing * i, -(pile_diameter * 0.5 - concrete_protect_layer - spiral_reinforcement_diameter * 0.1 * 3)), ref ext, "H钢筋", 2);

                PLPloter.AddLine(db,pt4.C2D(50 + outer_strengthen_reinforcement_spacing * i, 0), pt4.C2D(50 + outer_strengthen_reinforcement_spacing * i, 10), ref ext, "HM细线");

            }
            tuple = new Tuple<int, eDB, int, double>(4, N4, num4, 575.7);
            rebarLst.Add(tuple);
            #endregion

            #region 5#钢筋处理
            Point2d ptStart5 = insertPoint.C2D(-pile_length * 0.5, -30 * scale - pile_diameter * 0.5);
            for (int i = 1; i < num4; i++)
            {
                SteelBarS.CreateRib(db, ref ext, ptStart5.C2D(50 * 2 + 12 + outer_strengthen_reinforcement_spacing * i, pile_diameter * 0.5));
                SteelBarS.CreateRibDBTxt(db, ref ext, ptStart5.C2D(50 * 2 + 12 + outer_strengthen_reinforcement_spacing * i, pile_diameter * 0.5), outer_strengthen_reinforcement_spacing, true, scale);
                SteelBarS.CreateRib(db, ref ext, ptStart5.C2D(50 * 2 + 12 + outer_strengthen_reinforcement_spacing * i, -pile_diameter * 0.5), false);
                SteelBarS.CreateRibDBTxt(db, ref ext, ptStart5.C2D(50 * 2 + 12 + outer_strengthen_reinforcement_spacing * i, -pile_diameter * 0.5), outer_strengthen_reinforcement_spacing, false, scale);
                SteelBarS.CreateRibRec(db, ptStart5.C2D(50 * 2 + 12 + outer_strengthen_reinforcement_spacing * i), 23, 1.2, ref ext, "H钢筋");
                if (i == 4)
                {
                    Point2d ptD = ptStart5.C2D(50 * 2 + 12 + outer_strengthen_reinforcement_spacing * i, pile_diameter * 0.5);
                    SteelBarS.CreateRibRecMLeader(ptD, ptD.C2D(-10 * scale, 15 * scale), "DETAIL A", "ДЕТАЉ А", ref ext, scale, "HM细线");
                }
                //if (i == 6)
                //{
                //    Point2d ptD = ptStart5.C2D(50 * 2 + 12 + outer_strengthen_reinforcement_spacing * i, pile_diameter * 0.5);
                //    SteelBarS.CreateRibRecMLeader(ptD, ptD.C2D(-10 * scale, 15 * scale), "Distance keeper", "Држач растојења", ref ext, scale, "HM细线");
                //}
            }
            tuple = new Tuple<int, eDB, int, double>(5, N5, num4 * 4, 52);
            rebarLst.Add(tuple);
            #endregion
            rebarLst.Sort((a, b) => { return a.Item1.CompareTo(b.Item1); });
        }

        private void PlotPilePierSample(ref Database db, ref List<Extents2d> lstDetail, Point2d insertPoint, int scale, double w)
        {
            scale = 1;//绘制比例

            Extents2d extD, ext2, ext4, ext5;

            string dwgPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "Template\\RebarSerbia.dwg";
            extD = new Extents2d(insertPoint, insertPoint);
            double WL = w * 0.1;
            Point3d ptD = insertPoint.C3D(WL);
            //ext = new Extents2d(insertPoint, insertPoint);
            string _blcName = "DETAILA";
            BlockPlot.InsertBlockByDwg(db, dwgPath, _blcName, "H钢筋", ptD, ref extD, scale, 0, true, false);
            lstDetail.Add(extD);

            WL = w * 0.35;
            ptD = insertPoint.C3D(WL);
            ext5 = new Extents2d(ptD.C2D(), ptD.C2D());
            _blcName = "Rebar5";
            BlockPlot.InsertBlockByDwg(db, dwgPath, _blcName, "H钢筋", ptD, ref ext5, 0.5, 0, true, false);
            lstDetail.Add(ext5);

            WL = w * 0.75;
            ptD = insertPoint.C3D(WL);
            ext2 = new Extents2d(ptD.C2D(), ptD.C2D());
            //_blcName = "Rebar2";
            //BlockPlot.InsertBlockByDwg(db, dwgPath, _blcName, "H钢筋", ptD, ref ext2, 0.2, 0, true, false);

            double w2 = 30;
            double l2 = ext2.L();
            double sD = 0.3;
            Point2d ptS = ptD.C2D();
    
            Point2d bottomEnd = new Point2d();
            SteelBarS.CreatePartSteelBar(db, ref ext2, out bottomEnd, ptS, w2, bottom_encryption_spacing * sD * 6, bottom_encryption_spacing * sD, true, eLocation.Bottom);
            DimPloter.DimAli(db,ptD.C3D(0,w2*0.5), bottomEnd.C3D(), ptS.C3D(0, w2 * 0.5 + 5), ref ext2, scale, bottom_encryption_length.ToString(), Unit.Centimeter, Unit.Centimeter);
            DimPloter.DimAli(db,bottomEnd.C3D(bottom_encryption_spacing * sD * 2.5), bottomEnd.C3D( bottom_encryption_spacing * sD * 3.5), ptS.C3D(0, -w2 * 0.5 - 5), ref ext2, scale, bottom_encryption_spacing.ToString(), Unit.Centimeter, Unit.Centimeter);
            DimPloter.DimAli(db,ptD.C3D(0, w2 * 0.5), ptD.C3D(0, -w2 * 0.5), ptS.C3D( 5), ref ext2, scale, (pile_diameter-concrete_protect_layer*2-spiral_reinforcement_diameter*0.1).ToString(), Unit.Centimeter, Unit.Centimeter);

            Point2d middleEnd = new Point2d();
            SteelBarS.CreatePartSteelBar(db, ref ext2, out middleEnd, bottomEnd, w2, middle_encryption_spacing * sD * 4, middle_encryption_spacing * sD, true, eLocation.Middle);
            DimPloter.DimAli(db,middleEnd.C3D(), bottomEnd.C3D(), ptS.C3D(0, w2 * 0.5 + 5), ref ext2, scale, middle_encryption_length.ToString(), Unit.Centimeter, Unit.Centimeter);
            DimPloter.DimAli(db,middleEnd.C3D( middle_encryption_spacing * sD * 0.5), middleEnd.C3D( middle_encryption_spacing * sD * 1.5), ptS.C3D(0, -w2 * 0.5 - 5), ref ext2, scale, middle_encryption_spacing.ToString(), Unit.Centimeter, Unit.Centimeter);

            Point2d topEnd = new Point2d();
            SteelBarS.CreatePartSteelBar(db, ref ext2, out topEnd, middleEnd, w2, top_encryption_spacing * sD * 6, top_encryption_spacing * sD, true, eLocation.Top,false);
            DimPloter.DimAli(db,topEnd.C3D(), middleEnd.C3D(), ptS.C3D(0, w2 * 0.5 + 5), ref ext2, scale, top_encryption_length.ToString(), Unit.Centimeter, Unit.Centimeter);
            DimPloter.DimAli(db,topEnd.C3D( top_encryption_spacing * sD * 1.5), topEnd.C3D( top_encryption_spacing * sD * 2.5), ptS.C3D(0,-w2 * 0.5-5), ref ext2, scale, top_encryption_spacing.ToString(), Unit.Centimeter, Unit.Centimeter);

            Point2d topPier = new Point2d();
            SteelBarS.CreatePierPartSteelBar(db, ref ext2, out topPier, topEnd,w2, w2 * 0.8, pier_encryption_spacing * sD*4, pier_encryption_spacing * sD, true, eLocation.Top);
            DimPloter.DimAli(db,new Point3d(topPier.X, topEnd.Y,0), topEnd.C3D(), ptS.C3D(0, w2 * 0.5 + 5), ref ext2, scale, pier_encryption_length.ToString(), Unit.Centimeter, Unit.Centimeter);
            DimPloter.DimAli(db,topPier.C3D(pier_encryption_spacing * sD * 1.5), topPier.C3D(pier_encryption_spacing * sD * 2.5), ptS.C3D(0, -w2 * 0.5 - 5), ref ext2, scale, pier_encryption_spacing.ToString(), Unit.Centimeter, Unit.Centimeter);
            DimPloter.DimAli(db,topPier.C3D(), topPier.C3D(0, -w2 * 0.8), topPier.C3D(-5), ref ext2, scale, (pile_diameter - pier_protect_layer * 2 - spiral_reinforcement_diameter * 0.1).ToString(), Unit.Centimeter, Unit.Centimeter);

            SteelBarS.CreateSampleS(db, ref ext2, ptS.C2D(7+ w2*0.5), w2*0.5, spiral_reinforcement_diameter * 0.1, scale, "H钢筋");
            SteelBarS.CreateSampleS(db, ref ext2, topPier.C2D(-10 - w2 * 0.8 * 0.5, -w2 * 0.8*0.5), w2 *0.8* 0.5, spiral_reinforcement_diameter * 0.1, scale, "H钢筋");

            TextPloter.AddDBTextWithCirle(db,topPier.C3D(8, -w2 * 0.8*0.5-w2 * 0.5-9), ref ext2, "%%C"+spiral_reinforcement_diameter, "3", scale);

            TextPloter.AddDBTextWithCirle(db,middleEnd.C3D(8, -w2 - 9), ref ext2, "%%C" + spiral_reinforcement_diameter, "2", scale);
            lstDetail.Add(ext2);

            WL = w;
            ptD = insertPoint.C3D(WL);
            ext4 = new Extents2d(ptD.C2D(), ptD.C2D());
            _blcName = "Rebar4";
            BlockPlot.InsertBlockByDwg(db, dwgPath, _blcName, "H钢筋", ptD, ref ext4, 0.5, 0, true, false);
            lstDetail.Add(ext4);
        }

        /// <summary>
        /// 绘制截面
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="insertPoint"></param>
        /// <param name="scale"></param>
        public void PlotPilePierSection(ref Database db, out Extents2d ext, Point2d insertPoint, int scale)
        {
            double rebarLength = top_encryption_length + middle_encryption_length + bottom_encryption_length + concrete_protect_layer * 2;
            int divnum = (int)rebarLength / (1200 - 175);
            int divCap = (int)rebarLength % (1200 - 175);
            string num2 = "6";
            string num3 = "7";
            if (divnum == 0)
            {
                num2 = "6";
                num3 = "6";
            }
            else
            {
                num2 = "6";
                num3 = "7";
            }
           
            //scale = 5;//绘制比例
            ext = new Extents2d(insertPoint, insertPoint);
            ext = ext.Add(new Extents2d(insertPoint.C2D(-pile_diameter * 2.5), insertPoint.C2D(-pile_diameter * 2.5)));
            TextPloter.AddTitleS(db,insertPoint, ref ext, "CROSS SECTION 1-1", @"ПОПРЕЧНИ ПРЕСЕК 1-1", "(1:40)", scale);
            Point2d pt1 = insertPoint.C2D(0, -40 * scale - pile_diameter * 0.5);
            DrawSection(db, ref ext, pt1, scale, main_reinforcement_number, "1", top_encryption_spacing);

            double singleW = ext.W();
            Point2d pt2 = insertPoint.C2D(singleW + 30 * scale, 0);
            TextPloter.AddTitleS(db,pt2, ref ext, "CROSS SECTION 2-2", @"ПОПРЕЧНИ ПРЕСЕК 2-2", "(1:40)", scale);
            Point2d ptS2 = insertPoint.C2D(singleW + 30 * scale, -30 * scale - pile_diameter * 0.5);
            double len = 175;//搭接
            if (top_encryption_length + len < top_pile_reinforcement_length)
                DrawSection(db, ref ext, ptS2, scale, (int)(main_reinforcement_number), num2, middle_encryption_spacing);
            else
                DrawSection(db, ref ext, ptS2, scale, (int)(main_reinforcement_number * 0.5), num2, middle_encryption_spacing);

            Point2d pt3 = insertPoint.C2D(singleW * 2 + 30 * scale * 2, 0);
            ext = ext.Add(new Extents2d(pt3.C2D(pile_diameter * 2.5), pt3.C2D(pile_diameter * 2.5)));
            TextPloter.AddTitleS(db,pt3, ref ext, "CROSS SECTION 3-3", @"ПОПРЕЧНИ ПРЕСЕК 3-3", "(1:40)", scale);
            Point2d ptS3 = insertPoint.C2D(singleW * 2 + 30 * scale * 2, -30 * scale - pile_diameter * 0.5);
            if (top_encryption_length + middle_encryption_length + len * 2 < top_pile_reinforcement_length)
                DrawSection(db, ref ext, ptS3, scale, (int)(main_reinforcement_number), num3, bottom_encryption_spacing);
            else
                DrawSection(db, ref ext, ptS3, scale, (int)(main_reinforcement_number * 0.5), num3, bottom_encryption_spacing);
        }
    
        private void PlotPilePierCalculate(ref Database db, ref Extents2d ext, Point2d insertPoint, int scale = 1)
        {
            ext = new Extents2d(insertPoint, insertPoint);
            //TextPloter.AddTitleS(db,insertPoint, ref ext, "PILE REINFORCEMENT PLAN", @"ПЛАН АРМАТУРЕ ШИПОВАПИ", "(1:" + _scale + ")", scale);
            Point3d ptTable = insertPoint.C3D(0, 10 * scale);
            double volumn = Math.Ceiling(pile_length * 0.01 * Math.PI * pile_diameter * 0.5 * 0.01 * pile_diameter * 0.5 * 0.01);
            double height = 0;
            double width = 0;
            ModelTablePloter.DrawPileCalTable(db, ref ext, ptTable, ref height, ref width, Extensions.curFont, scale, rebarLst, reinforcement_grade, volumn);
            TextPloter.AddDBText(db,ptTable.C3D(width * 0.5, 10 * scale), ref ext, "Reinforcing steel schedule (One Pile - " + configure_name.ToUpper().Replace("PILE", "Pile") + ")", scale, 4, Extensions.curFont, 0, TextHorizontalMode.TextMid);
            TextPloter.AddDBText(db,ptTable.C3D(width * 0.5, 5 * scale), ref ext, "Шипке-спецификација (Један Гомила - Пристаниште " + configure_name.ToUpper().Replace("PILE", "") + ")", scale, 4, Extensions.curFont, 0, TextHorizontalMode.TextMid);

            string dwgPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "Template\\RebarSerbia.dwg";

            double WL = ext.W() + 10;
            Point3d ptD = insertPoint.C3D(WL, 25);
            //ext = new Extents2d(insertPoint, insertPoint);
            string _blcName = "ReferTb";
            BlockPlot.InsertBlockByDwg(db, dwgPath, _blcName, "H钢筋", ptD, ref ext, scale, 0, true, false);

            // 文字
            WL = ext.W() + 10;
            string text = "Notes:";
            Point3d p1 = insertPoint.C3D(WL, 15);
            TextPloter.AddMText(db,p1, ref ext, text, scale, 3, 3 * scale, Extensions.curFont);

            text = @"
     1. All dimensions are in centimeter except otherwise specified.
     2. All diameters of reinforcement in this drawing are all nominal diameter.
     3. Rings  ∅25 (No.4)  must be welded 100% to bars  ∅32 (No.1,No.3, and No.6). 
     4. Spiral stirrup ∅12 (No.2) must be welded 50% to bars ∅32 (No.1,No.3, and No.6).
     5. Spiral stirrup ∅12 (No.2 ) is made as a singular spiral stirrup.
     6. Outer dimensions and measures of bars are presented except for bar No.5 where central dimensions are presented.
     7. Bar No.5 should be modified to fit gap of spiral if necessary.";
            Point3d p2 = insertPoint.C3D(WL + 0.5, 13.5);
            TextPloter.AddMText(db,p2, ref ext, text, scale, 2.5, 120 * scale, Extensions.curFont);

            text = "Напомена:  ";
            Point3d p3 = insertPoint.C3D(WL, -30);
            TextPloter.AddMText(db,p3, ref ext, text, scale, 3, 3 * scale, Extensions.curFont);

            text = @"
     1.Све димензије на овом цртежу су у cm, осим ако другачије није назначено.
     2.Сви пречници арматуре на овом цртежу су номинални.
     3.Прстенове  ∅25 (No.4)  заварити 100%  за шипке  ∅32 (No.1,No.3, and No.6).
     4.Спиралу ∅12 (No.2 ) заварити 50% за шипке  ∅32 (No.1,No.3, and No.6). 
     5.Спирала (No.2 ) се изводи из једног дела.
     6.Приказане су спољње димензије и мере шипки осим за позицију 5
       за коју су дате централне димензије.
     7.Позицију No.5 потреби прилагодити ходу спирале.
";
            Point3d p4 = insertPoint.C3D(WL + 0.5, -33.5);
            TextPloter.AddMText(db,p4, ref ext, text, scale, 2.5, 150 * scale, Extensions.curFont);
        }

        #endregion
        #region  "桩基+承台"
        private void PlotPile(ref Database db, out Extents2d ext, Point2d insertPoint, int _scale)
        {
            eDB N2 = eDB.DB12;
            eDB N5 = eDB.DB12;
            eDB mainDB = (eDB)Enum.Parse(typeof(eDB), main_reinforcement_diameter.ToString());
            //eDB main = eDB.DB32;
            eDB N4 = (eDB)Enum.Parse(typeof(eDB), outer_strengthen_reinforcement_diameter.ToString());
            Tuple<int, eDB, int, double> tuple;

            double scale = _scale;//绘制比例
            ext = new Extents2d(insertPoint, insertPoint);
            TextPloter.AddTitleS(db,insertPoint, ref ext, "PILE REINFORCEMENT PLAN", @"ПЛАН АРМАТУРЕ ШИПОВАПИ", "(1:"+ _scale*10 + ")", scale);

            Point2d ptGZ = insertPoint.C2D(0, -30 * scale);
            #region 绘制轮廓
            //绘制桩基外轮廓
            PLPloter.AddPloy4(db, ptGZ, pile_length * 0.5, pile_length * 0.5, pile_diameter, ref ext, "HM细线");
            //绘制承台外轮廓
            PLPloter.AddPloy4(db, ptGZ.C2D(-pile_length * 0.5- pile_penetration_depth, pile_diameter * 0.3*0.5), pile_penetration_depth , pile_penetration_depth , pile_diameter+ pile_diameter*0.3, ref ext, "HM细线");
            DimPloter.DimAli(db,ptGZ.C3D(pile_length * 0.5, -30 * scale), ptGZ.C3D(-pile_length * 0.5, -30 * scale), ptGZ.C3D(0, 20 * scale), ref ext, scale,"", Unit.Centimeter, Unit.Centimeter);
            DimPloter.DimAli(db,ptGZ.C3D(-pile_length * 0.5, -30 * scale), ptGZ.C3D(-pile_length * 0.5 - pile_penetration_depth, - 30 * scale), ptGZ.C3D(0, 20 * scale), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
            #endregion

            #region 2号螺旋筋
            double h20 = 15 * scale;
            //绘制2号螺旋筋
            Point2d ptStart = insertPoint.C2D(pile_length * 0.5 - concrete_protect_layer*2, -30 * scale - pile_diameter * 0.5);
            Point2d ptStart0 = insertPoint.C2D(pile_length * 0.5 , -30 * scale - pile_diameter * 0.5);
            Point2d bottomEnd = new Point2d();
            SteelBarS.CreatePartSteelBar(db, ref ext, out bottomEnd, ptStart, pile_diameter- concrete_protect_layer*2- spiral_reinforcement_diameter * 0.1, bottom_encryption_length, bottom_encryption_spacing, true, eLocation.Bottom);
            Point2d ptLS = ptStart.C2D(0, -pile_diameter * 0.5 - pile_diameter * 0.3 * 0.5 - 20);
            PLPloter.AddLine(db,ptLS.C2D(), ptLS.C2D(-bottom_encryption_length), ref ext, "HM细线");
            Point3d txt21 = GeTools.MidPoint(ptLS.C3D(), ptLS.C3D(-bottom_encryption_length));
            TextPloter.AddDBTextWithCirle(db,txt21.C3D(0, -2.5 * scale), ref ext, (int)(bottom_encryption_length/bottom_encryption_spacing) + "%%C"+ spiral_reinforcement_diameter + "(t="+ bottom_encryption_spacing + ")", "2", scale);
            PLPloter.AddLine(db,ptLS.C2D(), ptLS.C2D(0,10), ref ext, "HM细线");
            PLPloter.AddLine(db,ptLS.C2D(-bottom_encryption_length), ptLS.C2D(-bottom_encryption_length, 10), ref ext, "HM细线");
            DimPloter.DimAli(db,ptLS.C3D(), ptLS.C3D(-bottom_encryption_length), ptLS.C3D(0, -h20),ref ext,scale,"", Unit.Centimeter, Unit.Centimeter);
            DimPloter.DimAli(db,ptStart.C3D(), ptStart0.C3D(), ptLS.C3D(0, -h20), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
            Point2d ptLS0 = insertPoint.C2D(pile_length * 0.5, -30 * scale - pile_diameter);
            DimPloter.DimAli(db,ptLS0.C3D(), ptLS0.C3D(0, pile_diameter), ptLS0.C3D(5*scale,0), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);

            Point2d middleEnd = new Point2d();
            SteelBarS.CreatePartSteelBar(db, ref ext, out middleEnd, bottomEnd, pile_diameter - concrete_protect_layer * 2 - spiral_reinforcement_diameter * 0.1, middle_encryption_length , middle_encryption_spacing, true, eLocation.Middle);
            ptLS = ptLS.C2D(-bottom_encryption_length);
            PLPloter.AddLine(db,ptLS.C2D(), ptLS.C2D(-middle_encryption_length), ref ext, "HM细线");
            Point3d txt22 = GeTools.MidPoint(ptLS.C3D(), ptLS.C3D(-middle_encryption_length));
            TextPloter.AddDBTextWithCirle(db,txt22.C3D(0, -2.5 * scale), ref ext, (int)(middle_encryption_length / middle_encryption_spacing) + "%%C" + spiral_reinforcement_diameter + "(t=" + middle_encryption_spacing + ")", "2", scale);
            PLPloter.AddLine(db,ptLS.C2D(), ptLS.C2D(0, 10), ref ext, "HM细线");
            PLPloter.AddLine(db,ptLS.C2D(-middle_encryption_length), ptLS.C2D(-middle_encryption_length, 10), ref ext, "HM细线");
            DimPloter.DimAli(db,ptLS.C3D(), ptLS.C3D(-middle_encryption_length), ptLS.C3D(0, -h20), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);

            Point2d topEnd = new Point2d();
            SteelBarS.CreatePartSteelBar(db, ref ext, out topEnd, middleEnd, pile_diameter - concrete_protect_layer * 2 - spiral_reinforcement_diameter * 0.1, top_encryption_length, top_encryption_spacing, true, eLocation.Top);
            ptLS = ptLS.C2D(-middle_encryption_length);
            PLPloter.AddLine(db,ptLS.C2D(), ptLS.C2D(-top_encryption_length), ref ext, "HM细线");
            Point3d txt23 = GeTools.MidPoint(ptLS.C3D(), ptLS.C3D(-top_encryption_length));
            TextPloter.AddDBTextWithCirle(db,txt23.C3D(0, -2.5 * scale), ref ext, (int)(top_encryption_length / top_encryption_spacing) + "%%C" + spiral_reinforcement_diameter + "(t=" + top_encryption_spacing + ")", "2", scale);
            PLPloter.AddLine(db,ptLS.C2D(), ptLS.C2D(0, 10), ref ext, "HM细线");
            PLPloter.AddLine(db,ptLS.C2D(-top_encryption_length), ptLS.C2D(-top_encryption_length, 10), ref ext, "HM细线");
            DimPloter.DimAli(db,ptLS.C3D(), ptLS.C3D(-top_encryption_length), ptLS.C3D(0, -h20), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
            TextPloter.AddDBText(db,topEnd.C3D(-2*scale,pile_diameter*0.1), ref ext, "PileCap", scale, 3, "SRB.HT", 0, TextHorizontalMode.TextRight,TextVerticalMode.TextBottom);

            #region 
            SteelBarS.CreateRibSection(db, ptStart0.C2D(-pile_length + 30, pile_diameter * 0.5 + 2 * scale),"1",ref ext,"H文本",scale);
            SteelBarS.CreateRibSection(db, ptStart0.C2D(-pile_length + 30, -pile_diameter * 0.5- 2 * scale), "1", ref ext, "H文本", scale);
            SteelBarS.CreateRibSection(db, ptStart0.C2D(-bottom_encryption_length - middle_encryption_length+middle_encryption_length * 0.1, pile_diameter * 0.5 + 2 * scale), "2", ref ext, "H文本", scale);
            SteelBarS.CreateRibSection(db, ptStart0.C2D(-bottom_encryption_length - middle_encryption_length+middle_encryption_length * 0.1, -pile_diameter * 0.5 - 2 * scale), "2", ref ext, "H文本", scale);
            SteelBarS.CreateRibSection(db, ptStart0.C2D(-bottom_encryption_length+bottom_encryption_length * 0.1, pile_diameter * 0.5 + 2 * scale), "3", ref ext, "H文本", scale);
            SteelBarS.CreateRibSection(db, ptStart0.C2D(-bottom_encryption_length+bottom_encryption_length * 0.1, -pile_diameter * 0.5 - 2 * scale), "3", ref ext, "H文本", scale);


            #endregion

            double tL=  GlobalFuncs.GetSpiralLength(top_encryption_length, spiral_reinforcement_diameter * 0.1, top_encryption_spacing , pile_diameter , concrete_protect_layer );
            double mL = GlobalFuncs.GetSpiralLength(middle_encryption_length , spiral_reinforcement_diameter * 0.1, middle_encryption_spacing, pile_diameter, concrete_protect_layer );
            double bL = GlobalFuncs.GetSpiralLength(bottom_encryption_length , spiral_reinforcement_diameter * 0.1, bottom_encryption_spacing , pile_diameter , concrete_protect_layer );
            double mT = GlobalFuncs.GetSpiralTopLength( spiral_reinforcement_diameter * 0.1, 0.5, pile_diameter, concrete_protect_layer);
            double L = (tL+mL+bL)+ mT*2;
            tuple = new Tuple<int, eDB, int, double>(2, N2, 1, L);
            rebarLst.Add(tuple);
            #endregion

            #region 1#,3#，6#钢筋，以及搭接动态绘制算法处理

            double len = 175;//搭接
            double h0 = 14 * scale;
            double h1 = 40 * scale;
            double h2 = 44 * scale;
            double h3 = 60 * scale;
            //绘制1号钢筋
            Point2d ptStart1 = insertPoint.C2D(pile_length * 0.5- concrete_protect_layer, -30 * scale - pile_diameter * 0.5);
            double rebarLength = top_encryption_length + middle_encryption_length + bottom_encryption_length+ concrete_protect_layer*2;
            PLPloter.AddLine(db,ptStart1.C2D(0, pile_diameter * 0.5 - concrete_protect_layer - spiral_reinforcement_diameter * 0.1 * 3), ptStart1.C2D(-rebarLength, pile_diameter * 0.5 - concrete_protect_layer - spiral_reinforcement_diameter * 0.1 * 3),ref ext,"H钢筋");
            PLPloter.AddLine(db,ptStart1.C2D(0, -(pile_diameter * 0.5 - concrete_protect_layer - spiral_reinforcement_diameter * 0.1 * 3)), ptStart1.C2D(-rebarLength, -(pile_diameter * 0.5 - concrete_protect_layer - spiral_reinforcement_diameter * 0.1 * 3)), ref ext, "H钢筋");
            double ang = Math.Round(360.0 / (main_reinforcement_number * 0.5), 2);
            double LB = 2 * (pile_diameter * 0.5 - concrete_protect_layer - main_reinforcement_diameter * 0.1) * Math.Sin(GeTools.DegreeToRadian(ang * 0.5));
            //搭接处理
            int divnum = (int)((rebarLength - len) / (1200 - len));
            int divCap = (int)((rebarLength- len)  % (1200 - len));
            if (rebarLength <= 1200)
            {
              
                PLPloter.AddLine(db,ptStart.C2D(-rebarLength, -pile_diameter - h0), ptStart.C2D(0, -pile_diameter - h0), ref ext, "H钢筋");
                Point3d txt10 = GeTools.MidPoint(ptStart.C3D(-rebarLength, -pile_diameter - h0), ptStart.C3D(0, -pile_diameter - h0));
                TextPloter.AddDBTextWithCirle(db,txt10.C3D(0, -2.5 * scale), ref ext, (int)(main_reinforcement_number * 0.5) + "%%C32/"+ LB.ToString("0.0"), "1", scale);
                TextPloter.AddDBText(db,txt10.C3D(), ref ext, "L=" + rebarLength.ToString("0.0"), scale, 2.5, "SRB.HT", 0, TextHorizontalMode.TextLeft);
                DimPloter.DimAli(db,ptStart.C3D(-rebarLength, -pile_diameter - h0), ptStart.C3D(0, -pile_diameter - 10 * scale), ptStart.C3D(0, -pile_diameter - h0 - 8 * scale), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
                if (top_pile_reinforcement_length > 0)
                {
                    PLPloter.AddLine(db,ptStart.C2D(-rebarLength, -pile_diameter - h1), ptStart.C2D(0, -pile_diameter - h1), ref ext, "H钢筋");
                    Point3d txt20 = GeTools.MidPoint(ptStart.C3D(-rebarLength, -pile_diameter - h1), ptStart.C3D(0, -pile_diameter - h1));
                    TextPloter.AddDBTextWithCirle(db,txt20.C3D(0, -2.5 * scale), ref ext, (int)(main_reinforcement_number * 0.5) + "%%C32/" + LB.ToString("0.0"), "1", scale);
                    TextPloter.AddDBText(db,txt20.C3D(), ref ext, "L=" + rebarLength.ToString("0.0"), scale, 2.5, "SRB.HT", 0, TextHorizontalMode.TextLeft);
                    DimPloter.DimAli(db,ptStart.C3D(-rebarLength, -pile_diameter - h1), ptStart.C3D(0, -pile_diameter - h1), ptStart.C3D(0, -pile_diameter - h1 + 8 * scale), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
                }
                tuple = new Tuple<int, eDB, int, double>(1, mainDB, main_reinforcement_number, rebarLength);
                rebarLst.Add(tuple);
            }
            else
            {
                string num = "1";
                for (int i = 0; i < divnum; i++)
                {                
                    if (i == 0)
                    {
                        num = "1";
                    }
                    else if (i < 2)
                    {
                        num = "3";
                    }
                    if (i % 2 == 0)
                    {
                        //if (i * (1200 - len) <= top_pile_reinforcement_length)
                        if ((i + 1) * (1200 - len) <= top_pile_reinforcement_length - len)
                        {
                            PLPloter.AddLine(db,ptStart.C2D(-rebarLength + (1200 - len) * i, -pile_diameter - h0), ptStart.C2D(-rebarLength + 1200 * (i + 1) - len * i, -pile_diameter - h0), ref ext, "H钢筋");
                            Point3d pttxt = GeTools.MidPoint(ptStart.C3D(-rebarLength + (1200 - len) * i, -pile_diameter - h0), ptStart.C3D(-rebarLength + 1200 * (i + 1) - len * i, -pile_diameter - h0));
                            TextPloter.AddDBTextWithCirle(db,pttxt.C3D(0, -2.5 * scale), ref ext, (int)(main_reinforcement_number * 0.5) + "%%C32/" + LB.ToString("0.0"), num, scale);
                            TextPloter.AddDBText(db,pttxt.C3D(), ref ext, "L=1200.0", scale, 2.5, "SRB.HT", 0, TextHorizontalMode.TextLeft);
                            DimPloter.DimAli(db,ptStart.C3D(-rebarLength + (1200 - len) * i, -pile_diameter - h0), ptStart.C3D(-rebarLength + 1200 * (i + 1) - len * i, -pile_diameter - h0), ptStart.C3D(0, -pile_diameter - h0 - 8 * scale), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
                        }
                        PLPloter.AddLine(db,ptStart.C2D(-rebarLength + (1200 - len) * i, -pile_diameter - h1), ptStart.C2D(-rebarLength + 1200 * (i + 1) - len * i, -pile_diameter - h1), ref ext, "H钢筋");
                        Point3d pttxt1 = GeTools.MidPoint(ptStart.C3D(-rebarLength + 1200 * i, -pile_diameter - h1), ptStart.C3D(-rebarLength + 1200 * (i + 1) - len * i, -pile_diameter - h1));
                        TextPloter.AddDBTextWithCirle(db,pttxt1.C3D(0, -2.5 * scale), ref ext, (int)(main_reinforcement_number * 0.5) + "%%C32/" + LB.ToString("0.0"), num, scale);
                        TextPloter.AddDBText(db,pttxt1.C3D(), ref ext, "L=1200.0", scale, 2.5, "SRB.HT", 0, TextHorizontalMode.TextLeft);
                        DimPloter.DimAli(db,ptStart.C3D(-rebarLength + (1200 - len) * i, -pile_diameter - h1), ptStart.C3D(-rebarLength + 1200 * (i + 1) - len * i, -pile_diameter - h1), ptStart.C3D(0, -pile_diameter - h1 + 8 * scale), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
                        DimPloter.DimAli(db,ptStart.C3D(-rebarLength + 1200 * (i + 1) - len * i, -pile_diameter - 36 * scale), ptStart.C3D(-rebarLength + (1200 - len) * (i + 1), -pile_diameter - 36 * scale), ptStart.C3D(-rebarLength + 1200, -pile_diameter - h1 + 13 * scale), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);

                    }
                    else
                    {
                        //if (i * (1200 - len) <= top_pile_reinforcement_length)
                        if ((i + 1) * (1200 - len) <= top_pile_reinforcement_length - len)
                        {
                            PLPloter.AddLine(db,ptStart.C2D(-rebarLength + (1200 - len) * i, -pile_diameter - h3), ptStart.C2D(-rebarLength + 1200 * (i + 1) - len * i, -pile_diameter - h3), ref ext, "H钢筋");
                            Point3d pttxt20 = GeTools.MidPoint(ptStart.C3D(-rebarLength + (1200 - len) * i, -pile_diameter - h3), ptStart.C3D(-rebarLength + 1200 * (i + 1) - len * i, -pile_diameter - h3));
                            TextPloter.AddDBTextWithCirle(db,pttxt20.C3D(0, 2.5 * scale), ref ext, (int)(main_reinforcement_number * 0.5) + "%%C32/" + LB.ToString("0.0"), num, scale);
                            TextPloter.AddDBText(db,pttxt20.C3D(0, -4 * scale), ref ext, "L=1200.0", scale, 2.5, "SRB.HT", 0, TextHorizontalMode.TextLeft);

                            DimPloter.DimAli(db,ptStart.C3D(-rebarLength + (1200 - len) * i, -pile_diameter - h3), ptStart.C3D(-rebarLength + 1200 * (i + 1) - len * i, -pile_diameter - h3), ptStart.C3D(0, -pile_diameter - h3 - 8 * scale), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
                        }
                        PLPloter.AddLine(db,ptStart.C2D(-rebarLength + (1200 - len) * i, -pile_diameter - h2), ptStart.C2D(-rebarLength + 1200 * (i + 1) - len * i, -pile_diameter - h2), ref ext, "H钢筋");
                        Point3d pttxt2 = GeTools.MidPoint(ptStart.C3D(-rebarLength + (1200 - len) * i, -pile_diameter - h2), ptStart.C3D(-rebarLength + 1200 * (i + 1) - len * i, -pile_diameter - h2));
                        TextPloter.AddDBTextWithCirle(db,pttxt2.C3D(0, 2.5 * scale), ref ext, (int)(main_reinforcement_number * 0.5) + "%%C32/" + LB.ToString("0.0"), num, scale);
                        TextPloter.AddDBText(db,pttxt2.C3D(0, -4 * scale), ref ext, "L=1200.0", scale, 2.5, "SRB.HT", 0, TextHorizontalMode.TextLeft);

                        DimPloter.DimAli(db,ptStart.C3D(-rebarLength + (1200 - len) * i, -pile_diameter - h2), ptStart.C3D(-rebarLength + 1200 * (i + 1) - len * i, -pile_diameter - h2), ptStart.C3D(0, -pile_diameter - h2 - 8 * scale), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
                        if (divCap > 0)
                            DimPloter.DimAli(db,ptStart.C3D(-rebarLength + 1200 * (i + 1) - len * i, -pile_diameter - h2), ptStart.C3D(-rebarLength + (1200 - len) * (i + 1), -pile_diameter - h2), ptStart.C3D(0, -pile_diameter - h1 + 13 * scale), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
                    }
                }
                if (divCap > 0)
                {
                    if (divnum == 0)
                        num = "1";
                    else if (divnum == 1)
                        num = "3";
                    else
                        num = "6";
                    if (divnum % 2 == 0)
                    {
                        if (divnum * (1200 - len) < top_pile_reinforcement_length- len)
                        {
                            PLPloter.AddLine(db,ptStart.C2D(-rebarLength + (1200 - len) * divnum, -pile_diameter - h0), ptStart.C2D(0, -pile_diameter - h0), ref ext, "H钢筋");
                            Point3d pttxt = GeTools.MidPoint(ptStart.C3D(-rebarLength + (1200 - len) * divnum, -pile_diameter - h0), ptStart.C3D(0, -pile_diameter - h0));
                            TextPloter.AddDBTextWithCirle(db,pttxt.C3D(0, -2.5 * scale), ref ext, (int)(main_reinforcement_number * 0.5) + "%%C32/29.4", num, scale);
                            TextPloter.AddDBText(db,pttxt.C3D(), ref ext, "L=" + (rebarLength - (1200 - len) * divnum).ToString("0.0"), scale, 2.5, "SRB.HT", 0, TextHorizontalMode.TextLeft);
                            DimPloter.DimAli(db,ptStart.C3D(-rebarLength + (1200 - len) * divnum, -pile_diameter - h0), ptStart.C3D(0, -pile_diameter - h0), ptStart.C3D(0, -pile_diameter - h0 - 8 * scale), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
                        }
                        PLPloter.AddLine(db,ptStart.C2D(-rebarLength + (1200 - len) * divnum, -pile_diameter - h1), ptStart.C2D(0, -pile_diameter - h1), ref ext, "H钢筋");
                        Point3d pttxt3 = GeTools.MidPoint(ptStart.C3D(-rebarLength + (1200 - len) * divnum, -pile_diameter - h1), ptStart.C3D(0, -pile_diameter - h1));
                        TextPloter.AddDBTextWithCirle(db,pttxt3.C3D(0, -2.5 * scale), ref ext, (int)(main_reinforcement_number * 0.5) + "%%C32/29.4", num, scale);
                        TextPloter.AddDBText(db,pttxt3.C3D(), ref ext, "L=" + (rebarLength - (1200 - len) * divnum).ToString("0.0"), scale, 2.5, "SRB.HT", 0, TextHorizontalMode.TextLeft);
                        DimPloter.DimAli(db,ptStart.C3D(-rebarLength + (1200 - len) * divnum, -pile_diameter - h1), ptStart.C3D(0, -pile_diameter - h1), ptStart.C3D(0, -pile_diameter - h1 + 8 * scale), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);

                    }
                    else
                    {
                        if (divnum * (1200 - len)< top_pile_reinforcement_length - len)
                        {
                            PLPloter.AddLine(db,ptStart.C2D(-rebarLength + (1200 - len) * divnum, -pile_diameter - h3), ptStart.C2D(0, -pile_diameter - h3), ref ext, "H钢筋");
                            Point3d pttxt20 = GeTools.MidPoint(ptStart.C3D(-rebarLength + (1200 - len) * divnum, -pile_diameter - h3), ptStart.C3D(0, -pile_diameter - h3));
                            TextPloter.AddDBTextWithCirle(db,pttxt20.C3D(0, 2.5 * scale), ref ext, (int)(main_reinforcement_number * 0.5) + "%%C32/29.4", num, scale);
                            TextPloter.AddDBText(db,pttxt20.C3D(0, -4 * scale), ref ext, "L=" + (rebarLength - (1200 - len) * divnum), scale, 2.5, "SRB.HT", 0, TextHorizontalMode.TextLeft);

                            DimPloter.DimAli(db,ptStart.C3D(-rebarLength + (1200 - len) * divnum, -pile_diameter - h3), ptStart.C3D(0, -pile_diameter - h3), ptStart.C3D(0, -pile_diameter - h3 - 8 * scale), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
                        }
                        PLPloter.AddLine(db,ptStart.C2D(-rebarLength + (1200 - len) * divnum, -pile_diameter - h2), ptStart.C2D(0, -pile_diameter - h2), ref ext, "H钢筋");
                        Point3d pttxt3 = GeTools.MidPoint(ptStart.C3D(-rebarLength + (1200 - len) * divnum, -pile_diameter - h2), ptStart.C3D(0, -pile_diameter - h2));
                        TextPloter.AddDBTextWithCirle(db,pttxt3.C3D(0, 2.5 * scale), ref ext, (int)(main_reinforcement_number * 0.5) + "%%C32/29.4", num, scale);
                        TextPloter.AddDBText(db,pttxt3.C3D(0, -4 * scale), ref ext, "L=" + (rebarLength - (1200 - len) * divnum).ToString("0.0"), scale, 2.5, "SRB.HT", 0, TextHorizontalMode.TextLeft);
                        DimPloter.DimAli(db,ptStart.C3D(-rebarLength + (1200 - len) * divnum, -pile_diameter - h2), ptStart.C3D(0, -pile_diameter - h2), ptStart.C3D(0, -pile_diameter - h2 - 8 * scale), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);

                    }
                }

            }
            int no1 = 1;
            int no3 = 3;
            int no6 = 6;
            if(divnum==0)
            {
                tuple = new Tuple<int, eDB, int, double>(no1, mainDB, main_reinforcement_number, rebarLength);
                rebarLst.Add(tuple);
            }
            else if(divnum == 1)
            {
                tuple = new Tuple<int, eDB, int, double>(no1, mainDB, main_reinforcement_number, 1200);
                rebarLst.Add(tuple);
               
                if (divCap > 0)
                {
                    if (divnum * (1200 - len) < top_pile_reinforcement_length- len)
                    {
                        tuple = new Tuple<int, eDB, int, double>(no3, mainDB, main_reinforcement_number, divCap+len);
                        rebarLst.Add(tuple);
                    }
                    else
                    {
                        tuple = new Tuple<int, eDB, int, double>(no3, mainDB, (int)(main_reinforcement_number*0.5), divCap + len);
                        rebarLst.Add(tuple);
                    }
                }
            
               
            }
            else
            {
                tuple = new Tuple<int, eDB, int, double>(no1, mainDB, main_reinforcement_number, 1200);
                rebarLst.Add(tuple);
                int count =( top_pile_reinforcement_length-len) % (1200 - len) == 0 ? (int)(top_pile_reinforcement_length / (1200 - len)) : (int)(top_pile_reinforcement_length / (1200 - len)) + 1;
                int numN3 = (count-1) * main_reinforcement_number+(divnum- count)*((int)(main_reinforcement_number*0.5));
                tuple = new Tuple<int, eDB, int, double>(no3, mainDB, numN3, 1200);
                rebarLst.Add(tuple);
               
                if (divCap > 0)
                {
                    if (divnum * (1200 - len)+len < top_pile_reinforcement_length)
                    {
                        tuple = new Tuple<int, eDB, int, double>(no6, mainDB, main_reinforcement_number, divCap + len);
                        rebarLst.Add(tuple);
                    }
                    else
                    {
                        tuple = new Tuple<int, eDB, int, double>(no6, mainDB, (int)(main_reinforcement_number * 0.5), divCap + len);
                        rebarLst.Add(tuple);
                    }
                }

            }
            //if (divCap > 0)
            //{
            //    if (divnum == 0)
            //        no = "1";
            //    else if (divnum == 1)
            //        no = "3";
            //    else
            //        no = "6";
            //}

            #endregion

            #region 4#钢筋处理
            Point2d ptStart4 = insertPoint.C2D(-pile_length * 0.5 , -30 * scale - pile_diameter * 0.5);
            Point2d pt4 = ptStart4.C2D(0, -pile_diameter * 0.5 - pile_diameter * 0.3 * 0.5 - 20-7*scale);
            int num4 = (int)(pile_length / outer_strengthen_reinforcement_spacing);
            Point3d txt4 = GeTools.MidPoint(pt4.C3D(50), pt4.C3D(50+ outer_strengthen_reinforcement_spacing*(num4-1)));
            TextPloter.AddDBTextWithCirle(db,txt4.C3D(0, -2.5 * scale), ref ext, num4 + "%%C25/" + outer_strengthen_reinforcement_spacing , "4", scale);

            Point2d ptStart40 = insertPoint.C2D(-pile_length * 0.5, -30 * scale - pile_diameter * 0.5 );
            for (int i = 1; i < num4; i++)
            {

                PLPloter.AddLine(db,pt4.C2D(50 + outer_strengthen_reinforcement_spacing * (i - 1), 0), pt4.C2D(50 + outer_strengthen_reinforcement_spacing * i, 0), ref ext, "HM细线");
                if (i == 1)
                {
                    PLPloter.AddLine(db,pt4.C2D(50, 0), pt4.C2D(50, 10), ref ext, "HM细线");
                    PLPloter.AddLineWithColor(db,ptStart40.C2D(50, pile_diameter * 0.5 - concrete_protect_layer - main_reinforcement_diameter * 0.1 - outer_strengthen_reinforcement_diameter * 0.1), ptStart40.C2D(50, -(pile_diameter * 0.5 - concrete_protect_layer - main_reinforcement_diameter * 0.1-outer_strengthen_reinforcement_diameter*0.1)), ref ext, "H钢筋",2);
                    PLPloter.AddLineWithColor(db,ptStart40.C2D(50 + outer_strengthen_reinforcement_spacing * i, pile_diameter * 0.5 - concrete_protect_layer - main_reinforcement_diameter * 0.1), ptStart40.C2D(50 + outer_strengthen_reinforcement_spacing * i, -(pile_diameter * 0.5 - concrete_protect_layer - main_reinforcement_diameter * 0.1)), ref ext, "H钢筋", 2);
                }
                else
                    PLPloter.AddLineWithColor(db,ptStart40.C2D(50+ outer_strengthen_reinforcement_spacing * i, pile_diameter * 0.5 - concrete_protect_layer - main_reinforcement_diameter * 0.1), ptStart40.C2D(50 + outer_strengthen_reinforcement_spacing * i, -(pile_diameter * 0.5 - concrete_protect_layer - main_reinforcement_diameter * 0.1)), ref ext, "H钢筋",2);

                PLPloter.AddLine(db,pt4.C2D(50 + outer_strengthen_reinforcement_spacing * i, 0), pt4.C2D(50 + outer_strengthen_reinforcement_spacing * i, 10), ref ext, "HM细线");

            }
            tuple = new Tuple<int, eDB, int, double>(4, N4, num4, 575.7);
            rebarLst.Add(tuple);
            #endregion

            #region 5#钢筋处理
            Point2d ptStart5 = insertPoint.C2D(-pile_length * 0.5, -30 * scale - pile_diameter * 0.5);
            for (int i = 0; i < num4; i++)
            {
                SteelBarS.CreateRib(db, ref ext, ptStart5.C2D(50 * 2 + 12+outer_strengthen_reinforcement_spacing * i, pile_diameter * 0.5));
                SteelBarS.CreateRibDBTxt(db, ref ext, ptStart5.C2D(50 * 2 + 12 + outer_strengthen_reinforcement_spacing * i, pile_diameter * 0.5), outer_strengthen_reinforcement_spacing, true, scale);
                SteelBarS.CreateRib(db, ref ext, ptStart5.C2D(50 * 2 + 12 + outer_strengthen_reinforcement_spacing * i, -pile_diameter * 0.5), false);
                SteelBarS.CreateRibDBTxt(db, ref ext, ptStart5.C2D(50 * 2 + 12 + outer_strengthen_reinforcement_spacing * i, -pile_diameter * 0.5), outer_strengthen_reinforcement_spacing, false, scale);
                SteelBarS.CreateRibRec(db, ptStart5.C2D(50 * 2 + 12 + outer_strengthen_reinforcement_spacing * i), 23, 1.2, ref ext, "H钢筋");
                if(i==4)
                {
                    Point2d ptD = ptStart5.C2D(50 * 2 + 12 + outer_strengthen_reinforcement_spacing * i, pile_diameter * 0.5);
                    SteelBarS.CreateRibRecMLeader(ptD, ptD.C2D(-10*scale, 15 * scale), "DETAIL A", "ДЕТАЉ А", ref ext, scale, "HM细线");
                }
                if (i == 6)
                {
                    Point2d ptD = ptStart5.C2D(50 * 2 + 12 + outer_strengthen_reinforcement_spacing * i, pile_diameter * 0.5);
                    SteelBarS.CreateRibRecMLeader(ptD, ptD.C2D(-10 * scale, 15 * scale), "Distance keeper", "Држач растојења", ref ext, scale, "HM细线");
                }
            }
            tuple = new Tuple<int, eDB, int, double>(5, N5, num4*4, 52);
            rebarLst.Add(tuple);
            #endregion
            rebarLst.Sort((a, b) => { return a.Item1.CompareTo(b.Item1); });
        }

        private void PlotSample(ref Database db, ref List<Extents2d> lstDetail, Point2d insertPoint, int scale,double w)
        {
            scale = 1;//绘制比例
          
            Extents2d extD, ext2, ext4, ext5;
            #region 方法一,dwg文件只包含独立块
            //string _dwgPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "Template\\RebarSerbia_DETAIL.dwg";
            //double WL = w * 0.05;
            //Point3d ptD = insertPoint.C3D(WL);

            ////SteelBarS.insert_block(_dwgPath, "H细线", _blcName, ptD, scale);
            //BlockPlot.InsertBlockFunc(db, _dwgPath, "H钢筋", ptD,ref ext,scale,0, true, false);
            //_dwgPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "Template\\RebarSerbia_Rebar5.dwg";

            //if (ext.W() + 2 * scale > (w * 0.25))
            //    WL = ext.W() + 2 * scale;
            //else
            //    WL = w * 0.25;
            //ptD = insertPoint.C3D(WL);
            //BlockPlot.InsertBlockFunc(db, _dwgPath, "H钢筋", ptD, ref ext, scale, 0, true, false);

            //_dwgPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "Template\\RebarSerbia_Rebar2.dwg";
            //if (ext.W() + 2 * scale > (w * 0.75))
            //    WL = ext.W() + 2 * scale;
            //else
            //    WL = w * 0.75;
            //ptD = insertPoint.C3D(WL);
            //BlockPlot.InsertBlockFunc(db, _dwgPath, "H钢筋", ptD, ref ext, scale, 0, true, false);

            //_dwgPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "Template\\RebarSerbia_Rebar4.dwg";

            //if (ext.W() + 2 * scale > (w ))
            //    WL = ext.W() + 2 * scale;
            //else
            //    WL = w;
            //ptD = insertPoint.C3D(WL);
            //BlockPlot.InsertBlockFunc(db, _dwgPath, "H钢筋", ptD, ref ext, scale, 0, true, false);
            #endregion


            string dwgPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "Template\\RebarSerbia.dwg";
            extD = new Extents2d(insertPoint, insertPoint);
            double WL = w * 0.1;
            Point3d ptD = insertPoint.C3D(WL);
            //ext = new Extents2d(insertPoint, insertPoint);
            string _blcName = "DETAILA";
            BlockPlot.InsertBlockByDwg(db, dwgPath, _blcName, "H钢筋", ptD, ref extD, scale, 0, true, false);
            lstDetail.Add(extD);

            WL = w * 0.35;
            ptD = insertPoint.C3D(WL);
            ext5 = new Extents2d(ptD.C2D(), ptD.C2D());
            _blcName = "Rebar5";
            BlockPlot.InsertBlockByDwg(db, dwgPath, _blcName, "H钢筋", ptD, ref ext5, 0.5, 0, true, false);
            lstDetail.Add(ext5);

            WL = w * 0.75;
            ptD = insertPoint.C3D(WL);
            ext2 = new Extents2d(ptD.C2D(), ptD.C2D());
            _blcName = "Rebar2";
            BlockPlot.InsertBlockByDwg(db, dwgPath, _blcName, "H钢筋", ptD, ref ext2, 0.2, 0, true, false);
            double w2 = ext2.W()*0.6;
            double l2 = ext2.L();
            double sD = 0.2;
            Point2d ptS = ptD.C2D(-w2*0.25, -l2 * 1.1- bottom_encryption_spacing * sD * 6 - middle_encryption_spacing * sD * 4 - top_encryption_spacing * sD * 8);
            Point2d ptStart = ptS.C2D(0,bottom_encryption_spacing * sD * 6);
            Point2d ptStart0 = ptS.C2D();
            Point2d bottomEnd = new Point2d();
            SteelBarS.CreatePartSteelBar(db, ref ext2, out bottomEnd, ptS, w2, bottom_encryption_spacing * sD * 6, bottom_encryption_spacing * sD, false, eLocation.Bottom);
            DimPloter.DimAli(db,ptStart.C3D(), ptStart0.C3D(), ptS.C3D(w2 ), ref ext2, scale, bottom_encryption_length.ToString(), Unit.Centimeter, Unit.Centimeter);
            DimPloter.DimAli(db,bottomEnd.C3D(-w2,-bottom_encryption_spacing * sD * 2.5), bottomEnd.C3D(-w2,-bottom_encryption_spacing * sD * 3.5), ptS.C3D(-w2*0.7), ref ext2, scale, bottom_encryption_spacing.ToString(), Unit.Centimeter, Unit.Centimeter);

            Point2d middleEnd = new Point2d();
            SteelBarS.CreatePartSteelBar(db, ref ext2, out middleEnd, bottomEnd, w2, middle_encryption_spacing * sD * 4, middle_encryption_spacing * sD, false, eLocation.Middle);
            DimPloter.DimAli(db,middleEnd.C3D(), bottomEnd.C3D(), ptS.C3D(w2 ), ref ext2, scale, middle_encryption_length.ToString(), Unit.Centimeter, Unit.Centimeter);
            DimPloter.DimAli(db,middleEnd.C3D(-w2, - middle_encryption_spacing * sD * 0.5), middleEnd.C3D(-w2, -middle_encryption_spacing * sD * 1.5), ptS.C3D(-w2 * 0.7), ref ext2, scale, middle_encryption_spacing.ToString(), Unit.Centimeter, Unit.Centimeter);

            Point2d topEnd = new Point2d();
            SteelBarS.CreatePartSteelBar(db, ref ext2, out topEnd, middleEnd, w2, top_encryption_spacing * sD * 8, top_encryption_spacing * sD, false, eLocation.Top);
            DimPloter.DimAli(db,topEnd.C3D(), middleEnd.C3D(), ptS.C3D(w2), ref ext2, scale, top_encryption_length.ToString(), Unit.Centimeter, Unit.Centimeter);
            DimPloter.DimAli(db,topEnd.C3D(-w2, - top_encryption_spacing * sD * 1.5), topEnd.C3D(-w2, -top_encryption_spacing * sD * 2.5), ptS.C3D(-w2 * 0.7), ref ext2, scale, top_encryption_spacing.ToString(), Unit.Centimeter, Unit.Centimeter);

            lstDetail.Add(ext2);

            WL = w;
            ptD = insertPoint.C3D(WL);
            ext4 = new Extents2d(ptD.C2D(), ptD.C2D());
            _blcName = "Rebar4";
            BlockPlot.InsertBlockByDwg(db, dwgPath, _blcName, "H钢筋", ptD, ref ext4, 0.5, 0, true, false);
            lstDetail.Add(ext4);
        }

        /// <summary>
        /// 绘制截面
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="insertPoint"></param>
        /// <param name="scale"></param>
        public void PlotSection(ref Database db, out Extents2d ext, Point2d insertPoint, int scale)
        {
            double rebarLength = top_encryption_length + middle_encryption_length + bottom_encryption_length + concrete_protect_layer * 2;
            int divnum = (int)rebarLength / (1200 - 175);
            int divCap = (int)rebarLength % (1200 - 175);
            string num2 = "3";
            string num3 = "6";
            if (divnum == 0)
            {
                num2 = "1";
                num3 = "1";
            }
            else if (divnum == 1)
            {
                num2 = "3";
                num3 = "3";
            }
            else
            {
                num2 = "3";
                num3 = "6";
            }
            //scale = 5;//绘制比例
            ext = new Extents2d(insertPoint, insertPoint);
            ext = ext.Add(new Extents2d(insertPoint.C2D(-pile_diameter*2.5), insertPoint.C2D(-pile_diameter * 2.5)));
            TextPloter.AddTitleS(db,insertPoint, ref ext, "CROSS SECTION 1-1", @"ПОПРЕЧНИ ПРЕСЕК 1-1", "(1:40)", scale);
            Point2d pt1 = insertPoint.C2D(0, -40 * scale - pile_diameter * 0.5);
            DrawSection(db, ref ext, pt1, scale, main_reinforcement_number,"1",top_encryption_spacing);

            double singleW = ext.W();
            Point2d pt2 = insertPoint.C2D(singleW + 30* scale, 0);
            TextPloter.AddTitleS(db,pt2, ref ext, "CROSS SECTION 2-2", @"ПОПРЕЧНИ ПРЕСЕК 2-2", "(1:40)", scale);
            Point2d ptS2 = insertPoint.C2D(singleW + 30 * scale, -30 * scale - pile_diameter * 0.5);
            double len = 175;//搭接
            if (top_encryption_length+ len < top_pile_reinforcement_length)
                DrawSection(db, ref ext, ptS2, scale, (int)(main_reinforcement_number), num2,middle_encryption_spacing);
            else
                DrawSection(db, ref ext, ptS2, scale, (int)(main_reinforcement_number * 0.5), num2, middle_encryption_spacing);

            Point2d pt3 = insertPoint.C2D(singleW * 2 + 30 * scale * 2,0);
            ext = ext.Add(new Extents2d(pt3.C2D(pile_diameter * 2.5), pt3.C2D(pile_diameter * 2.5)));
            TextPloter.AddTitleS(db,pt3, ref ext, "CROSS SECTION 3-3", @"ПОПРЕЧНИ ПРЕСЕК 3-3", "(1:40)", scale);
            Point2d ptS3 = insertPoint.C2D(singleW * 2 + 30 * scale * 2, -30 * scale - pile_diameter * 0.5);
            if (top_encryption_length+middle_encryption_length+ len*2 < top_pile_reinforcement_length)
                DrawSection(db, ref ext, ptS3, scale, (int)(main_reinforcement_number), num3,bottom_encryption_spacing);
            else
                DrawSection(db, ref ext, ptS3, scale, (int)(main_reinforcement_number * 0.5), num3, bottom_encryption_spacing);
        }

        public void DrawSection(Database db, ref Extents2d ext, Point2d pt1, int scale,int main_number,string mainNo="1",double encryption_spacing=15)
        {
            //N5  eDB.12 对应直径
            PLPloter.AddCircle(db, pt1, pile_diameter * 0.5 + 2 * concrete_protect_layer, ref ext, "HM细线");
            Arc arcCal = new Arc(pt1.C3D(), pile_diameter * 0.5, GeTools.DegreeToRadian(0), GeTools.DegreeToRadian(360));
            Line lineCal = new Line(pt1.C3D(-pile_diameter * 0.5, pile_diameter * 0.5), pt1.C3D(pile_diameter * 0.5, -pile_diameter * 0.5));
            List<Point3d> node = new List<Point3d>();
            MathExtensions.LineIntersectArc(lineCal, arcCal, ref node);

            //Line line = PLPloter.AddLine(db,pt1.C2D(-pile_diameter * 0.5), pt1.C2D(-pile_diameter * 0.5), ref ext, "HM细线");
            Line line1 = new Line(pt1.C3D(-pile_diameter * 0.5 - concrete_protect_layer * 2), pt1.C3D(-pile_diameter * 0.5 - concrete_protect_layer));
            List<Entity> lst= ArrayPloter.ArrayPolarEntity(line1, db, main_number, 360, pt1.C3D(), "HM细线");
            Line lDim;
            if (lst.Count > 2)
                lDim = (Line)lst[lst.Count-2];
            else
                lDim = (Line)lst[lst.Count-1];
            double ang = Math.Round(360.0/ main_number, 2);
            double L = 2*(pile_diameter*0.5- concrete_protect_layer-main_reinforcement_diameter*0.1) * Math.Sin(GeTools.DegreeToRadian(ang *0.5));
            Point3d ptM10 = lDim.StartPoint;
            Point3d ptM11 = lDim.EndPoint;
            SteelBarS.CreateRibMLeader(GeTools.MidPoint(ptM10, ptM11).C2D(), ptM10.C2D(-pile_diameter * 0.2, pile_diameter * 0.2), main_number + "%%C"+main_reinforcement_diameter+"/"+L.ToString("0.0"), mainNo, ref ext, scale, "HM细线");

            PLPloter.AddCircle(db, pt1, pile_diameter * 0.5, ref ext, "HM细线");
            Line line5 = new Line(pt1.C3D(-pile_diameter * 0.5), pt1.C3D(-pile_diameter * 0.5 + concrete_protect_layer + spiral_reinforcement_diameter * 0.1)) { ColorIndex = 4 };
            ArrayPloter.ArrayPolarEntity(line5, db, 4, 360, pt1.C3D(), "H钢筋");
            Point2d ptDim2= GeTools.PointRotate(pt1, pt1.C2D(-pile_diameter * 0.5 + concrete_protect_layer + spiral_reinforcement_diameter * 0.1), 100);
            SteelBarS.CreateRibMLeader(ptDim2, ptDim2.C2D(pile_diameter * 0.3, pile_diameter * 0.3), "U%%C"+ spiral_reinforcement_diameter + "(t=" + encryption_spacing + ")", "2", ref ext, scale, "HM细线");


            SteelBarS.CreateRibMLeader(pt1.C2D(-pile_diameter * 0.5 + concrete_protect_layer*0.5), pt1.C2D(-pile_diameter * 0.7,-pile_diameter*0.7), "%%C12/"+outer_strengthen_reinforcement_spacing,"5",ref ext,scale,"HM细线");
            SteelBarS.CreateRibMLeader(pt1.C2D(0, pile_diameter * 0.5 - concrete_protect_layer * 0.5), pt1.C2D(-pile_diameter * 0.3 , pile_diameter * 0.8), "%%C12/" + outer_strengthen_reinforcement_spacing, "5", ref ext, scale, "HM细线");
            SteelBarS.CreateRibMLeader(pt1.C2D(pile_diameter * 0.5 - concrete_protect_layer * 0.5), pt1.C2D(pile_diameter * 0.7, -pile_diameter * 0.2), "%%C12/" + outer_strengthen_reinforcement_spacing, "5", ref ext, scale, "HM细线");
            SteelBarS.CreateRibMLeader(pt1.C2D(0, -pile_diameter * 0.5 + concrete_protect_layer * 0.5), pt1.C2D(pile_diameter * 0.2 , -pile_diameter * 0.7), "%%C12/" + outer_strengthen_reinforcement_spacing, "5", ref ext, scale, "HM细线");

         
            if (node.Count > 1)
            {
                DimPloter.DimRot(db, node[0].C3D(), node[1].C3D(), pt1.C3D(), ref ext, 135, scale, "%%C" + pile_diameter);
            }
            PLPloter.AddCircle(db, pt1, pile_diameter * 0.5 - concrete_protect_layer- spiral_reinforcement_diameter * 0.1, ref ext, "H钢筋");
            Circle circle = new Circle(pt1.C3D(-pile_diameter * 0.5 + concrete_protect_layer + spiral_reinforcement_diameter * 0.1 + 5 * 0.5), Vector3d.ZAxis, 2) { ColorIndex = 6 };
            ArrayPloter.ArrayPolarEntity(circle, db, main_number, 360, pt1.C3D());
            PLPloter.AddCircle(db, pt1, pile_diameter * 0.5 - concrete_protect_layer - spiral_reinforcement_diameter * 0.1 - 5, ref ext, "H钢筋");

            Point2d ptDim4 = GeTools.PointRotate(pt1, pt1.C2D(-pile_diameter * 0.5 + concrete_protect_layer + spiral_reinforcement_diameter * 0.1 + 5 ), 130);
            SteelBarS.CreateRibMLeader(ptDim4, ptDim4.C2D(pile_diameter * 0.2, pile_diameter * 0.2), "%%C" +outer_strengthen_reinforcement_diameter+ "/"+outer_strengthen_reinforcement_spacing, "4", ref ext, scale, "HM细线");

        }

        private void PlotCalculate(ref Database db, ref Extents2d ext, Point2d insertPoint, int scale=1)
        {
            ext = new Extents2d(insertPoint, insertPoint);
            //TextPloter.AddTitleS(db,insertPoint, ref ext, "PILE REINFORCEMENT PLAN", @"ПЛАН АРМАТУРЕ ШИПОВАПИ", "(1:" + _scale + ")", scale);
            Point3d ptTable = insertPoint.C3D(0, 10 * scale);
            double volumn =Math.Ceiling( pile_length*0.01*Math.PI * pile_diameter * 0.5 * 0.01 * pile_diameter * 0.5 * 0.01);
            double height = 0;
            double width = 0;
            ModelTablePloter.DrawPileCalTable(db,ref ext, ptTable, ref height,ref width, Extensions.curFont, scale, rebarLst, reinforcement_grade, volumn);
            TextPloter.AddDBText(db,ptTable.C3D(width * 0.5, 10 * scale), ref ext, "Reinforcing steel schedule (One Pile - "+ configure_name.ToUpper().Replace("PILE", "Pile") + ")", scale, 4, Extensions.curFont, 0, TextHorizontalMode.TextMid);
            TextPloter.AddDBText(db,ptTable.C3D(width * 0.5, 5 * scale), ref ext, "Шипке-спецификација (Један Гомила - Пристаниште " + configure_name.ToUpper().Replace("PILE","") + ")", scale, 4, Extensions.curFont, 0, TextHorizontalMode.TextMid);

            string dwgPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "Template\\RebarSerbia.dwg";
     
            double WL = ext.W()+10;
            Point3d ptD = insertPoint.C3D(WL,25);
            //ext = new Extents2d(insertPoint, insertPoint);
            string _blcName = "ReferTb";
            BlockPlot.InsertBlockByDwg(db, dwgPath, _blcName, "H钢筋", ptD, ref ext, scale, 0, true, false);

            // 文字
            WL = ext.W() + 10;
            string text = "Notes:";
            Point3d p1 = insertPoint.C3D(WL, 15);
            TextPloter.AddMText(db,p1, ref ext, text, scale, 3, 3 * scale, Extensions.curFont);

            text = @"
     1. All dimensions are in centimeter except otherwise specified.
     2. All diameters of reinforcement in this drawing are all nominal diameter.
     3. Rings  ∅25 (No.4)  must be welded 100% to bars  ∅32 (No.1,No.3, and No.6). 
     4. Spiral stirrup ∅12 (No.2) must be welded 50% to bars ∅32 (No.1,No.3, and No.6).
     5. Spiral stirrup ∅12 (No.2 ) is made as a singular spiral stirrup.
     6. Outer dimensions and measures of bars are presented except for bar No.5 where central dimensions are presented.
     7. Bar No.5 should be modified to fit gap of spiral if necessary.";
            Point3d p2 = insertPoint.C3D(WL+0.5, 13.5);
            TextPloter.AddMText(db,p2, ref ext, text, scale, 2.5, 170 * scale, Extensions.curFont);

            text = "Напомена:  ";
            Point3d p3 = insertPoint.C3D(WL, -30);
            TextPloter.AddMText(db,p3, ref ext, text, scale, 3, 3 * scale, Extensions.curFont);

            text = @"
     1.Све димензије на овом цртежу су у cm, осим ако другачије није назначено.
     2.Сви пречници арматуре на овом цртежу су номинални.
     3.Прстенове  ∅25 (No.4)  заварити 100%  за шипке  ∅32 (No.1,No.3, and No.6).
     4.Спиралу ∅12 (No.2 ) заварити 50% за шипке  ∅32 (No.1,No.3, and No.6). 
     5.Спирала (No.2 ) се изводи из једног дела.
     6.Приказане су спољње димензије и мере шипки осим за позицију 5
       за коју су дате централне димензије.
     7.Позицију No.5 потреби прилагодити ходу спирале.
";
            Point3d p4 = insertPoint.C3D(WL + 0.5, -33.5);
            TextPloter.AddMText(db,p4, ref ext, text, scale, 2.5, 150 * scale, Extensions.curFont);
        }
       
        #endregion
    }

}
